gpt4 book ai didi

PHP mysqli_fetch_array 如何转到下一行?

转载 作者:行者123 更新时间:2023-11-30 01:18:13 24 4
gpt4 key购买 nike

我有一个 php 和 mysql 脚本,我想在其中根据 mysql 表中找到的值创建不同的结果。

我将 horas 数组中的 te 值与该行的 hora 变量的值进行比较。如果我做其他事情,它也会做其他事情。然而我的疑问是,在 if 中,当条件为真时,我如何更改到下一行?

$con = db_connect();


$result = mysqli_query($con,"SELECT * FROM projetor WHERE data = '$mydate' AND hora = '$hora'");

$horas=array("a","b","c","d","e","f","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x");

$arrlength=count($horas);

while($row = mysqli_fetch_array($result)){

$cod = $row['cod'];
$data = $row['data'];
$hora = $row['hora'];

$professor = $row['professor'];
$sala = $row['sala'];


for($x=0;$x<$arrlength;$x++)
{

if ($horas[$x] == $hora){

echo "<tr>";

echo "<td>" .$professor . "</td>";

echo "</tr>";

next($row);//how to go to next row??
}
else{

$h=$horas[$x];
$professor ="<a href='add_reserva.php?hora=$h&mydate=$mydate'>Requisitar</a>";
echo "<tr>";
echo "</tr>";


}
}

}

最佳答案

您不需要调用任何 next 方法,此代码会为您完成此操作:

while($row = mysqli_fetch_array($result)){

(已编辑)由于您的 while 循环中有一个 for 循环迭代,因此您可以放置​​一个 break; 来结束您的内部 for 循环,这将开始 while 循环的下一次迭代(这将转到 SQL 结果的下一行)

关于PHP mysqli_fetch_array 如何转到下一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836721/

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