Advertisement

08.24.2008 at 10:28AM PDT, ID: 23673830 | Points: 500
[x]
Attachment Details

PHP rand() and mt_rand() query

Asked by melvinbrad20 in PHP Scripting Language, PHP and Databases, MySQL Server

Tags:

Hi, I'm looking for a better way to generate a random row using rand() or mt_rand().

I was told that mt_rand() was better but I do not know how to use it in a query.

Basically, I need a better QUERY that will make sure each row gets pulled.

Here is my query but it sometimes some rows do not get selected.Start Free Trial
1:
$row = mysql_fetch_object(mysql_query("SELECT * FROM websites, plus_signup WHERE plus_signup.credits>0 AND websites.userid = plus_signup.userid AND plus_signup.userid NOT LIKE '$userid' ORDER BY RAND() LIMIT 1"));
[+][-]08.24.2008 at 12:30PM PDT, ID: 22301771

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2008 at 07:24AM PDT, ID: 22387690

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628