gpt4 book ai didi

php - 通知: Unidentified Index: QNo in C:\\xampp\htdocs\,

转载 作者:行者123 更新时间:2023-11-29 23:43:08 25 4
gpt4 key购买 nike

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

注意:未识别的索引:QNo in C:\xampp\htdocs\,......

请有人给出此错误的解决方案

<?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> ";
}
...

此外,我想您的表中有几个问题,但我没有看到任何循环,也许您忘记发布它......

关于php - 通知: Unidentified Index: QNo in C:\\xampp\htdocs\,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26073844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com