我有这个数组
$row4 = mysql_fetch_array($sql_res);
有没有人能告诉我如何获得$row4['response']的随机值
$row4没有常量值...
但是现在$row4包含了
Array ( [0] => 3 [id] => 3 [1] => where is dryad [react] => where is dryad [2] => Dryad is found in the farthest part of the Dark wilderness. [response] => Dryad is found in the farthest part of the Dark wilderness. [3] => [review] => ) 1发布于 2012-04-04 09:07:42
因为您的代码现在是正确的,所以您只能返回一个查询行。此行将只包含该行的字段值。如果您确实只是尝试从该单行中获取随机字段值,则可以使用:
$randomKey = array_rand($row4,1);如果您打算从查询中请求随机行,则可以使用以下两种方法之一:
1)使用array_rand抓取随机行并放入$randomRow
while($row = mysql_fetch_array($sql_res)) $rows[] = $row;
$randomRow = array_rand($rows);2)在您的查询中,您可以指定只抓取一个随机行,而不是每个结果:
SELECT col1 FROM tbl ORDER BY RAND() LIMIT 1;
https://stackoverflow.com/questions/10003557
复制相似问题