Page 1 of 1

Array from mysql rows?

Posted: Fri Nov 25, 2005 4:13 am
by Echilon
Is it possible to read the results of a query that finds multiple rows into an array. I know how to read fields into an array, but what about rows? At the moment, I have this

Code: Select all

$quotenumsql = "SELECT `quote` FROM `quotes`"; 
$quotenumqry = mysql_query($quotenumsql) or die(mysql_error()); 
$numquotes = mysql_num_rows($quotenumqry); 
$quoteary = mysql_fetch_array($quotenumqry, MYSQL_NUM);
$quotearysize = count($quoteary); 
//get quote 
$quotenumber = rand(0, $numquotes-1);
$quote = $quoteary[$quotenumber];
But when I echo $quotearysize, it returns 1, instead of the 15 rows in the database. I know the SQL is correct because I check it with phpmyadmin and 15 rows were returned. I just need to get these 15 rows into an array, with 1 row per array value.

Posted: Fri Nov 25, 2005 4:26 am
by shiznatix

Code: Select all

$quotenumsql = "SELECT `quote` FROM `quotes`";
$quotenumqry = mysql_query($quotenumsql) or die(mysql_error());

while ($quoteary = mysql_fetch_assoc($quotenumqry)
{
  $quotes[] = $quoteary['quote'];
}

echo '<pre>';
print_r($quotes);
echo '</pre>';
try that. i think you just need the while loop if i did not read this wrong.

Posted: Fri Nov 25, 2005 4:39 am
by Echilon
Thanks alot for that, it works fine now :mrgreen: