php - Fetch array with mysql_fetch_assoc -
$query = mysql_query("select name lottery"); // make lotteries array $queryarray = mysql_fetch_array($query); // each lottery, store name of in $lottery foreach ($queryarray $lottery) { // select ids of tickets in current selected lottery ($lottery) $ticketquery = mysql_query("select id tickets lottery='$lottery'"); // create array ids $ticketarray = mysql_fetch_assoc($ticketquery); // select random id, our winner ticket $winner = $ticketarray[array_rand($ticketarray)]; }
when run this, however, error:
"warning: array_rand() [function.array-rand]: first argument has array in public_html/php/lotterypick.php on line 25"
have tried replace
mysql_fetch_assoc
mysql_fetch_array
, hasn't helped either. given me same error. ideas? thanks. line 25: $winner = $ticketarray[array_rand($ticketarray)];
writing code as:
while($lottery = mysql_fetch_array($query)){...}
would solve problem.
Comments
Post a Comment