我正在尝试从SQL数据库($ demo)存储变量($ q11),但出现错误

注意:身份不明的索引:C:\ xampp \ htdocs \,...中的QNo。

请有人给这个错误的解决方案

<?php
$connect = mysql_connect("localhost","root","")
or die(mysql_error());
$sel=mysql_select_db("demo");

$query1 = mysql_query("SELECT * FROM `linuxq`  ORDER BY RAND() LIMIT 10 ");

echo "<h4 align='Center'><u>Linux Questions</u><br></h4>";

$rows11 = mysql_fetch_array($query1);
$q11 = $rows11['QNo'];
$qus11 = $rows11['Question'];
$a = $rows11['Opt1'];
$b = $rows11['Opt2'];
$c = $rows11['Opt3'];
$d = $rows11['Opt4'];
$ans11 = $rows11['Ans'];


echo " <b>Question:-<br></b>$qus11 <br>";
echo " <input type=radio name = 'answer$q11' value = '$a'></input>$a &nbsp &nbsp";
echo " <input type=radio name = 'answer$q11' value = '$b'></input>$b &nbsp &nbsp";
echo " <input type=radio name = 'answer$q11' value = '$c'></input>$c &nbsp &nbsp ";
echo " <input type=radio name = 'answer$q11' value = '$d'></input>$d <br><br> ";

最佳答案

无论如何,为了避免出现不必要的错误消息,您应该通过添加以下内容来检查查询的记录数:

...
$query1 = mysql_query("SELECT * FROM `linuxq`  ORDER BY RAND() LIMIT 10 ");
echo "<h4 align='Center'><u>Linux Questions</u><br></h4>";

if(mysql_num_rows($query1)>0) {
  $rows11 = mysql_fetch_array($query1);
  $q11 = $rows11['QNo'];
  $qus11 = $rows11['Question'];
  $a = $rows11['Opt1'];
  $b = $rows11['Opt2'];
  $c = $rows11['Opt3'];
  $d = $rows11['Opt4'];
  $ans11 = $rows11['Ans'];

  echo " <b>Question:-<br></b>$qus11 <br>";
  echo " <input type=radio name = 'answer$q11' value = '$a'></input>$a &nbsp &nbsp";
  echo " <input type=radio name = 'answer$q11' value = '$b'></input>$b &nbsp &nbsp";
  echo " <input type=radio name = 'answer$q11' value = '$c'></input>$c &nbsp &nbsp ";
  echo " <input type=radio name = 'answer$q11' value = '$d'></input>$d <br><br> ";
}
...


此外,我想您的表中有几个问题,但我看不到任何循环,也许您忘了发帖了……

10-05 19:53