how to check if mysql query return no result(record not found) using php?

前端 未结 3 544
鱼传尺愫
鱼传尺愫 2020-12-17 06:13

i am passing images file names via textarea to php script to find information about each image in mysql db .The problem is i am trying to output those image file names that

相关标签:
3条回答
  • 2020-12-17 06:32

    You want to use mysqli_num_rows

    if(mysqli_num_rows($result)) {
       // Do your while loop here
    }
    
    0 讨论(0)
  • 2020-12-17 06:42

    You can use mysqli_num_rows() in mysqli

    if(mysqli_num_rows($result) > 0){
    
        while($row = mysqli_fetch_array($result))
        {
            $totalRows++;
    
            echo "<tr>";
            echo "<td>" . $row['ID'] ."(".$totalRows. ")</td>";
            echo "<td>" . $row['name'] . "</td>";
            echo "<td>" . $row['imgPURL'] . "</td>";
            echo "<td>" . $row['imgUrl'] . "</td>";  
            echo "</tr>";         
        }
    } else {
        echo "<tr><td colspan='4'>Not Found Image:".$line.'</td></tr>';
    }
    
    0 讨论(0)
  • 2020-12-17 06:46

    Use mysqli_num_rows to compare the number of rows in the result set.

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