PHP mysqli_fetch_array how to go to next row?

こ雲淡風輕ζ 提交于 2019-12-13 04:30:12

问题


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


              }
      }

  }

回答1:


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)




回答2:


Use the continue command:

continue;

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



来源:https://stackoverflow.com/questions/18836721/php-mysqli-fetch-array-how-to-go-to-next-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!