MySQL querying table - Doesn't show first result

前端 未结 1 1634
無奈伤痛
無奈伤痛 2021-01-28 23:32

I have a DB (quartos) created with the following structure:

id_quarto  tipo_quarto  vista_quarto |
a      Single   Mar | 
b      Single   Mar |
c      Single   M         


        
相关标签:
1条回答
  • 2021-01-29 00:15

    You have extra $row = mysql_fetch_array($rs); just after mysql_query($strSQL);. Then in while loop you read $row again (second row in resultset). So your code will look

    $strSQL = "SELECT id_quarto FROM quartos 
      WHERE tipo_quarto='". $_POST['tipo_quarto'] ."' 
      AND vista_quarto='". $_POST['vista_quarto'] ."'";
    $rs = mysql_query($strSQL);
    // $row = mysql_fetch_array($rs); Don't need this line!!!
    while($row = mysql_fetch_array($rs)) 
    {
       // output ....
    }
    

    Also, it always makes sense to add code for handling mysql errors.

    0 讨论(0)
提交回复
热议问题