MySQL Forums
Forum List  »  PHP

Re: RAND() issue
Posted by: daniel praid
Date: September 20, 2005 05:27PM

I think I've ended up solving my issue myself using another sql query and a touch of php:

// Grab all of the quotes from the relevent class (2)
$sql = mysql_query("SELECT * FROM quotes WHERE class=2 ORDER BY id ASC");

// Get the total number of rows from the above sql
$num_rows = mysql_num_rows($sql);

// setup a while loop to go through each sql row to see if it matches the last quote
while ($quotestat = mysql_fetch_array($sql)) {

// creates a value for each row encountered and increses it by one each time we loop
$i++;

// if the quote id is the same as the quote id of the rand() quote then grab the $i value
if ($sqlquote['id'] == $quotestat['id']) {
$num_quote = $i;
}
}


now all I do is: $quotestat = "quote ".$num_quote." of ".$num_rows.": ";

If anyone comes up with a better solution or can see an error let me know, cheers!



Edited 2 time(s). Last edit at 09/20/2005 05:31PM by daniel praid.

Options: ReplyQuote


Subject
Written By
Posted
September 20, 2005 04:22PM
Re: RAND() issue
September 20, 2005 05:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.