Re: Random question selection in PHP w/ MySQL backend.
| From: | John Pickett | Date: | Tue, 31 Jul 2001 20:47:28 +0000 |
| Subject: | Re: Random question selection in PHP w/ MySQL backend. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-10936@lists.php.net to get a copy of this message | ||
Adam,
I'm what I would call a novice to PHP and databases in general, however if I
had to do what you're doing, I might do the following...
Add a field to the table that contains your questions called "displayed" and
have it be an enum of Yes/No True/False, etc... In your script, you'd then
query for all the questions that haven't already been displayed. Then get a
random one of those (plenty of randomizing functions in PHP I believe).
Display it, mark it as displayed in the db... Next time, it won't even get
returned in the query. I don't know if you have to do this on a per-user
basis or what. If so, you will probably have to create a session table and
keep track of the questions each user has viewed... Hope this gets you
started... Cheers!
My 2 ¢
John Pickett
http://www.bvstudios.com/
Co-Author: Inside Dreamweaver 4
http://www.amazon.com/exec/obidos/ASIN/0735710848/xtremist
----- Original Message -----
From: "Adam Lundrigan" <ceo@vpu-virtual.com>
To: <php-db@lists.php.net>
Sent: Tuesday, July 31, 2001 2:32 PM
Subject: [PHP-DB] Random question selection in PHP w/ MySQL backend.
I'm having a bit of trouble creating a random question selector. I'm using
PHP 4.0.6 and MySQL 3.23.36 on Windows 98 SE.
I've tried several different solutions, but none work at all.
What i need to do is select 10 questions from a database (db: vpt, table:
questions), and make sure that the same question doesn't appear twice. The
questions need to appear in a random order each time the script is loaded.
It sounds simple enough, but i just can't seem to get it to work.
Any suggestions??
Thanks in advance,
-Adam Lundrigan
CEO, VPU
http://www.vpu-virtual.com/
ICQ # 73617446
ceo@vpu-virtual.com