반응형
mysql db의 각 이미지에 대한 정보를 찾기 위해 textarea를 통해 이미지 파일 이름을 php 스크립트에 전달하고 있습니다. 문제는 mysql db에서 찾을 수없는 이미지 파일 이름을 출력하고 사용자에게 찾을 수없는 이미지 파일 이름을 알리려고한다는 것입니다. mysql. 내 현재 코드는 누락 된 레코드를 db에 출력하지 못하지만 db에서 찾은 이미지에 대한 정보를 올바르게 출력합니다. 아무도 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까?
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;
해결 방법
mysqli에서 mysqli_num_rows ()
를 사용할 수 있습니다.
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>';
}
참조 페이지 https://stackoverflow.com/questions/20063068
반응형
'MySql' 카테고리의 다른 글
MySQL 오류 1452 MySQL (0) | 2020.12.17 |
---|---|
MySQL pip-3.3 install MySQL-python (0) | 2020.12.17 |
MySQL 패키지 요구 사항 : libcurl.so.3 (0) | 2020.12.17 |
MySQL Laravel 데이터베이스 스키마의 MediumBlob (0) | 2020.12.16 |
MySQL Write current time plus 5 minutes in MySql from PHP (0) | 2020.12.16 |
댓글