我编写了一个从 MySQL 查询中检索值的 PHP 脚本。我使用 mysql_fetch_array 将结果添加到数组中。我正在尝试从数组中选择一个随机值,但是 array_rand 似乎不起作用。我的代码如下:
<?php
session_start();
ob_start();
require_once 'includes/db_connection.php';
require_once 'includes/contest.php';
require_once 'includes/survey.php';
require_once 'includes/poll.php';
require_once 'includes/clients.php';
require_once 'includes/user.php';
//Select All Entries from Contest and Save as Array
//Select
mysql_connect(localhost,s2ktest_s2kuser, Bc33iyZYQWgUmguBehPI);
$dbname = 's2ktest_s2k';
mysql_select_db($dbname);
$contestid = 20;
$query = "SELECT UserID FROM Contest_Entered WHERE ContestID = $contestid";
//Save Result
$result = mysql_query($query) or die(mysql_error());
//Save All Contest Entries in Array
$entries = mysql_fetch_array($result) or die(mysql_error());
//Output all Rows
//While Each Entry in the Array is a Value
while($entries = mysql_fetch_array($result))
{
echo $entries;
echo "</br>";
}
echo array_rand($entries);
//mysql_free_result($result);
?>