我的PHP while循环($row=mysql\u fetch\u array($query));显示多次而不是一次
该表将每个课程显示五次(查询课程的数量)。我只希望根据If-else语句每个显示一次。请问我的代码有什么问题我的PHP while循环($row=mysql\u fetch\u array($query));显示多次而不是一次,php,mysql,Php,Mysql,该表将每个课程显示五次(查询课程的数量)。我只希望根据If-else语句每个显示一次。请问我的代码有什么问题 <?php $query = mysql_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456'"); while ($row = mysql_fetch_array($query)) { if ($row['lesson'] == "Reproduc
<?php
$query = mysql_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456'");
while ($row = mysql_fetch_array($query)) {
if ($row['lesson'] == "Reproductive system 01a")
{
echo 'Reproductive system 01a Completed ';
}
else
{
echo '<a href="file:///D|/CC-Gate/localhost">Reproductive system 01a</a>';
}
}
?>
<?php
$query = mysql_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456'");
while ($row = mysql_fetch_array($query)) {
if ($row['index_no'] !== '456' && $row['lesson'] !== "Fertilisation process") { // this is redundant as your query handles this
echo '<a href="file:///D|/CC-Gate/localhost">Fertilisation process</a>';
} else {
echo 'Fertilisation process Completed';
}
}
?>
此代码正在运行:
<?php
$query = mysql_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456'");
while ($row = mysql_fetch_array($query)) {
if ($row['index_no'] !== '456' && $row['lesson'] !== "pregnancy") { // this is redundant as your query handles this
echo '<a href="file:///D|/CC-Gate/localhost">pregnancy</a>';
} else {
echo 'pregnancy Completed ';
}
}
?>
<?php
$query = mysql_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456'");
while ($row = mysql_fetch_array($query)) {
if ($row['lesson'] == "Birth process")
{
echo 'Birth process Completed ';
}
else
{
echo '<a href="file:///D|/CC-Gate/localhost">Birth process </a>Birth process Completed ';
}
}
?>
您很可能有相同索引号的重复行 这个查询显示了多少个结果
SELECT index_no, count(index_no) as duplicate FROM c8_lessons_list WHERE index_no ='456' GROUP BY index_no
您必须消除重复数据(删除旧行),然后向索引添加唯一的键索引。\u no
===
编辑:
好吧,在你的评论中,你在这行中有一个错误,mysqli需要2个参数
$query = mysqli_query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456' && lesson='Reproductive system 01a'");
这是因为在mysqli中,您必须引用连接,例如:
$sql = $mysqli->query("SELECT index_no, lesson FROM c8_lessons_list WHERE index_no ='456' && lesson='Reproductive system 01a'") or die (mysqli_errro($mysqli));
其中,$mysqli
是您的连接,例如:
$mysqli = @mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die("Server Overloaded. Please try again in a few moments!");
“生殖系统01a”表中有多少课程可用,而“生殖系统01a”课程仅一次显示正确?请勿使用
mysql\u*
它已被删除,不再工作。改为使用PDO
或MySQLi
。我只希望代码显示“课程已完成”或显示课程的超链接(如果尚未完成)。获取错误“警告:mysqli_query()需要至少2个参数,1个在第68行的H:\xampp\htdocs\bps_register\bps_menu\u fadinglink\u test01.php中给定警告:mysqli_fetch\u array()预期参数1为mysqli_result,在第71行的H:\xampp\htdocs\bps_register\bps_menu\u fadinglink\u test01.php中为空。这是我无法理解的问题代码。“$query=mysqli_查询(“选择索引号,来自c8_课程列表的课程,其中索引号为456'&&lesson='REGINATIONAL system 01a');而($row=mysqli_fetch_array($query)){if($row['index_no']='456'和&$row['lesson']==“生殖系统01a”){echo'生殖系统01a已完成';}否则{echo';}“运行查询时会发生什么:选择索引号,c8课程列表中的课程,其中索引号为456和生殖系统01a
来自phpmyadmin或其他管理工具?