I'm using the following to select some photo, how do I incorporate 'IF EXISTS' so i can echo some text if no ID is found.
$Result = mysql_query("SELECT * FROM photos WHERE UID = '$ID' limit 30")
if (mysql_num_rows($Result)) echo "You have photos!";
else echo "Dude... take some photos!";
When no ID is found, the $Result will contain 0 values.
Now you can ask, how many values $Result contains with mysql_num_rows() function like this:
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
}
}
Here's what i ended up doing.
<?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.'
';
}
?>