2016-05-29 20 views
1

沒有結果時,我想顯示「沒有該活動的門票」,否則顯示票據數據。沒有找到結果返回的信息

Waht代碼有誤嗎?

   <?php 

     $result = mysqli_query($con,"SELECT * FROM ticket WHERE eventID = ".$_GET['eventID'] ." ORDER by ticketEDate ASC"); 
     while($row = mysqli_fetch_array($result, MYSQL_BOTH)) { 

           if (mysqli_num_rows($result) ==0){ 
             echo "There are no tickets for this event"; 
            } else { 

         echo '<tr> 
           <td><h8>Ticket voor: </h8><h8a>'. $row['ticketName'] .'</h8a></td><br> 

           <td><h4><strong>Begin verkoop:</strong> &nbsp; ',date("d.m.Y", strtotime ($row['ticketSDate'])),' &nbsp; ', date('H:i', strtotime ($row['ticketSTime'])).' hr.<h4></td> 
           <td><h4><strong>Einde verkoop:</strong> &nbsp; ',date("d.m.Y", strtotime ($row['ticketEDate'])),' &nbsp; ', date('H:i', strtotime ($row['ticketETime'])).' hr.<h4></td> 
           <td><h5><strong>Beschrijving:</strong></color> &nbsp;'. $row['ticketDescription'] .'</h5></td> 
           <td><h4><strong>Event ID:</strong> &nbsp;'. $row['eventID'] .' '. $row['eventName'] .'</h4></td>   

           <form action="registratie.php" method="get"> 
           <td><h4>'. $row['ticketID'] .' <input name="book" type="submit" value="Kies dit ticket" /> 

           <input type="hidden" name="ticketID" value="'.$row['ticketID'].'"> 
           </form> 

           <br><br> 
          </tr>'; 
        } 
       } 
      ?> 

回答

2

移動if (mysqli_num_rows($result) ==0){while -loop

if (mysqli_num_rows($result) == 0){ 
    echo "There are no tickets for this event"; 
} else { 
    while ($row = mysqli_fetch_array($result, MYSQL_BOTH)) { 
     // render rows 
    } 
} 
+0

正確的,我忽略了這一個!謝謝,本尼 – Benny

0

因爲int 被認爲false,我們可以使用:

if(!empty(mysqli_num_rows($result))){ 
    while($row = mysqli_fetch_array($result)) { 
    //... 
    } 
}else{ 
    echo "There are no tickets for this event"; 
}