我正在尝试创建一个测试。这是我的表格作为php数组:
/**
* Database `soru_arsivi`
*/
/* `soru_arsivi`.`cevaplar` */
$cevaplar = array(
array('cevap_id' => '1','cevap_icerik' => 'was','yanlis_cevaplar' =>
'wasn\'t / were / weren\'t'),
array('cevap_id' => '2','cevap_icerik' => 'wasn\'t','yanlis_cevaplar' =>
'was / were / weren\'t')
);
到目前为止我的代码:
$cevaplar = "SELECT yanlis_cevaplar, cevap_icerik FROM cevaplar";
$cevap_sonuc = $conn->query($cevaplar) or die(mysqli_error($conn));
$result = $cevap_sonuc->fetch_all(MYSQLI_ASSOC);
$siklar = array_rand($result, 4);
foreach ($result as $siklar) {
echo "<li>a)" . $result[$siklar[0]] . "</li>";
echo "<li>b)" . $result[$siklar[1]] . "</li>";
echo "<li>c)" . $result[$siklar[2]] . "</li>";
echo "<li>d)" . $result[$siklar[3]] . "</li>";
}
问题是我收到这些错误消息:
警告:array_rand():第二个参数必须介于1和之间 数组中的元素数量 第59行的C:\ xampp \ htdocs \ appro \ admin \ sorularabak.php
注意:未定义的偏移量:0英寸 第62行的C:\ xampp \ htdocs \ appro \ admin \ sorularabak.php
注意:未定义的索引:in 第62行的C:\ xampp \ htdocs \ appro \ admin \ sorularabak.php
它出了什么问题:)
答案 0 :(得分:0)
array_rand ( array $array [, int $num = 1 ] )
$num
Specifies how many entries should be picked.
我认为你获得了结果中的行数
$siklar = array_rand($result, mysqli_num_rows ($cevap_sonuc ));