Hi there,
I'm trying to work out the best way to grab one random result, from an SQL query, from a list of many results.
Basically, what I'm trying to achieve is to select any given number of quotes from the table and then randomly chose one of them to use/
I'm guessing that the reults from the query have to go into a an array, each result requiring a number associated to it and then doing a rand() to grab that random result.
What I have so far is:
$sql = "SELECT * FROM test_quotes
ORDER BY quote_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain quote information.", '', __LINE__, __FILE__, $sql);
}
$quotesrow = array();
while ( $row = $db->sql_fetchrow($result) )
{
$quotesrow[] = $row;
}
$db->sql_freeresult($result);
Does anyone have an example of achieving this or know how to achieve this from by adding code to the code above?.
Thanks. 🙂