Php SQL Rand()提供了resultset,但无法获取结果

Php SQL Rand()提供了resultset,但无法获取结果,php,mysql,sql,Php,Mysql,Sql,我在做一个sql查询,它从表中给出随机行。我的目标是每次都得到随机排序的结果集,它在android中与volley一起使用,有时它给出正确的结果,工作正常,有时不工作,它不会给出json结果,但仍然会有类似“mysqli_result Object([current_field]=>0[field_count]=>8[Length]=>[num_rows]=>10[type]=>0)“这是rand()的问题吗?没有rand,它可以正常工作,但我需要表中的随机行我需要随机选择的特定数量的行,还有其

我在做一个sql查询,它从表中给出随机行。我的目标是每次都得到随机排序的结果集,它在android中与volley一起使用,有时它给出正确的结果,工作正常,有时不工作,它不会给出json结果,但仍然会有类似“mysqli_result Object([current_field]=>0[field_count]=>8[Length]=>[num_rows]=>10[type]=>0)“这是rand()的问题吗?没有rand,它可以正常工作,但我需要表中的随机行我需要随机选择的特定数量的行,还有其他方法吗

<?php
  include_once("config.php");
 $r = mysqli_query($db,"Select * from qs ORDER BY RAND()
LIMIT 10");
print_r($r);
  $result = array();
 while($row = mysqli_fetch_array($r)){ 
array_push($result,array(
 "id"=>$row[0],
 "question"=>$row[1],
  "option1"=>$row[2],
 "option2"=>$row[3],
  "option3"=>$row[4],
 "option4"=>$row[5],
"answer"=>$row[6]

 )
 );
}
 echo json_encode(array("result"=>$result));
 ?>

问题在于我的字符编码是UTF-8,我将其改为UTF8 $db->set_字符集(“utf8”)



i认为它没有向结果数组中添加值下面的操作正常$r1=mysqli_query($db,“Select*from qs ORDER BY RAND()LIMIT 10”);$projects=array();而($row=mysqli_fetch_row($r1)){printf(%s(%s)\n',$row[0],$row[1])}得到了实际的问题是echo json_编码(数组(“result”=>$result));$result数组已包含元素
<?php

include_once("config.php");
$db->set_charset("utf8");
 $r = mysqli_query($db,"Select * from qs ORDER BY RAND() LIMIT 10");
  $result = array();
 while($row = mysqli_fetch_array($r)){   
array_push($result,array(
 "id"=>$row[0],
 "question"=>$row[1],
  "option1"=>$row[2],
 "option2"=>$row[3],
  "option3"=>$row[4],
 "option4"=>$row[5],
"answer"=>$row[6]

 )
 );
}
  echo json_encode(array("result"=>$result)); 
?>