2013-12-12 18 views

回答

0
if (mysql_num_rows($Result)) echo "You have photos!"; 
else echo "Dude... take some photos!"; 
+0

如果ID存在,你会找到行,所以在ID不存在的情况下,num_rows将不返回任何内容。所以我们必须先检查ID是否存在。 – Relm

+0

假设您有一个包含用户标识(UID)的表,为什么不只是查询有效的用户标识? '$ Result = mysql_query(“SELECT UID FROM users WHERE UID ='$ ID'limit 1”);'' –

0

当无法找到ID,在$结果将包含0值。

现在你可以问,$结果多少值包含mysql_num_rows()功能是这样的:

if (mysql_num_rows($Result) == 0) echo "No Photo with $ID found"; 
else { 
    while($photo = mysql_fetch_object($Result)) { 
      //Here $photo contains a photo with the UID $ID 
    } 
} 
0

这是我落得这样做。

<?php 
$data = preg_replace ('#[^0-9 ]#i', '', $_POST['data']); 
require_once 'db_conx.php'; 
$Result = mysql_query("SELECT * FROM photos WHERE pid = '$data' limit 30") 
or die (mysql_error()); 
while($row = mysql_fetch_array($Result)){ 
$NoPhotos = (empty($row['photo'])) ? 'This Business Profile has no photos, you can send this business a message and ask them to upload some ' : ''; 
$Photos = (!empty($row['photo'])) ? '<img width="32%" height="70" src="'.$row['photo'].'" class="ProPhotosID">' : ''; 
echo ' 
'.$NoPhotos.''.$Photos.' 
'; 
} 
?> 
相关问题