$query = mysql_query("SELECT Name from lottery");
// Make All Lotteries Into An Array
$queryarray = mysql_fetch_array($query);
// For Each Lottery, Store the Name of It in $lottery
foreach ($queryarray as $lottery) {
// Select IDs of Tickets in Current Selected Lottery ($lottery)
$ticketquery = mysql_query("SELECT id FROM tickets WHERE lottery='$lottery'");
// Create an Array from the IDS
$ticketarray = mysql_fetch_assoc($ticketquery);
// Select A Random ID, This Is Our Winner Ticket
$winner = $ticketarray[array_rand($ticketarray)];
}
When I run this, however, I get this error:
"Warning: array_rand() [function.array-rand]: First argument has to be an array in public_html/php/lotterypick.php on line 25"
I have tried to replace
mysql_fetch_assoc with mysql_fetch_array and that hasn't helped much either. Just given me the same error. Any ideas? Thanks.
Line 25: $winner = $ticketarray[array_rand($ticketarray)];
var_dump($queryarray);die;before the loop, and see what it contains... it does not contain what you think it contains.