Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2006, 10:53 AM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default no repeat selection!

Hi I've got this code for selecting a number of questions from a db to make a test. It's random and sometimes it selects the same questions and they appear twice in the tests... how can I stop this from happening?

$sql = "SELECT * FROM questions ORDER BY RAND() LIMIT 20";

thanks in advance!

 
Old February 18th, 2006, 12:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure but perhaps you can the DISTINCT keyword... E.g. look here...

http://www.google.com/search?hl=en&q=sql+distinct&meta=

Hope it helps, Jacob.
 
Old February 18th, 2006, 01:17 PM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$sql = "SELECT DISTINCT *, id FROM questions ORDER BY RAND() LIMIT 20";

thanks! this code did the trick!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
'Repeat' a stored procedure Shaneus BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 February 14th, 2008 06:49 AM
XSLT - Don't Repeat if last record mattboy_slim XSLT 2 September 11th, 2007 12:33 PM
InStr() repeat instances spinout Classic ASP Components 7 November 23rd, 2006 11:55 AM
Sort a repeat region hendricksonet VBScript 0 August 11th, 2005 01:55 PM
Repeat Region with a difference. fatmcgav Dreamweaver (all versions) 2 January 17th, 2005 05:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.