PHP mysqli_fetch_array how to go to next row?

2019-08-27 01:40发布

I have a php and mysql script, where I want to create different results based on the values found in mysql table.

I compare te value in the horas array to the value of my hora variable of the row. If it this same I do something else, it does other. However my doubt is, in the if, when the condition is true how do I change to the next row?

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


              }
      }

  }

标签: php html mysql row
2条回答
该账号已被封号
2楼-- · 2019-08-27 01:59
你好瞎i
3楼-- · 2019-08-27 02:10

You don't need to call any next method, this code does that for you:

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

(Edited) Since you have a for-loop iteration inside your while-loop, you can put a break; that will end your inner for-loop, which will start the next iteration of your while-loop (which will go to the next row of your SQL result)

查看更多
登录 后发表回答