$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)];
}


但是,当我运行此命令时,出现以下错误:“警告:array_rand()[function.array-rand]:第一个参数必须是第25行的public_html / php / lotterypick.php中的数组”
我试图用mysql_fetch_assoc替换mysql_fetch_array,但也没有太大帮助。只是给了我同样的错误。有任何想法吗?谢谢。

第25行:$winner = $ticketarray[array_rand($ticketarray)];

最佳答案

将代码编写为:

while($lottery = mysql_fetch_array($query)){...}


会解决问题。

关于php - 使用mysql_fetch_assoc获取数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29321563/

10-09 23:07