dongle19863 2013-11-19 04:13
浏览 101
已采纳

如何检查mysql查询是否使用PHP返回没有结果(记录未找到)?

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 not found in mysql db and inform the user which image file names not found in mysql. my current code fails to output those missing records in db but it correctly outputs information about those images found in db. could any one tell me what i am doing wrong ?

foreach ($lines as $line) {


$line = rtrim($line);


$result = mysqli_query($con,"SELECT ID,name,imgUrl,imgPURL FROM testdb WHERE imgUrl like '%$line'");            



 if (!$result) {
             die('Invalid query: ' . mysql_error());
            }
//echo $result;

  if($result == 0) 
    {

       // image not found, do stuff..
      echo "Not Found Image:".$line; 
    }



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


}

};

echo "</table>";

echo "<br>totalRows:".$totalRows;
  • 写回答

3条回答 默认 最新

  • douchuilai2355 2013-11-19 04:17
    关注

    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>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站