0

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

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

$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>";


              }
      }

  }
4

2 回答 2

2

您不需要调用任何next方法,此代码为您执行此操作:

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

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

于 2013-09-16T20:31:04.420 回答
-2

使用继续命令:

continue;

http://php.net/manual/en/control-structures.continue.php

于 2013-09-16T20:32:16.927 回答