Php 没有结果返回时的消息

Php 没有结果返回时的消息,php,Php,当没有结果返回时,我喜欢显示“此事件没有票证”,否则显示票证数据 代码有什么问题吗 <?php $result = mysqli_query($con,"SELECT * FROM ticket WHERE eventID = ".$_GET['eventID'] ." ORDER by ticketEDate ASC"); while($row = mysqli_fetch_array($result, MYSQL_BO

当没有结果返回时,我喜欢显示“此事件没有票证”,否则显示票证数据

代码有什么问题吗

                <?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>';
                    }
                }
            ?> 

Move
if(mysqli_num_rows($result)==0){
之外,而
-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
     }
}

由于
int
0被视为
false
,因此我们可以使用:

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

没错,我忽略了这个!!谢谢,本尼