Reputation: 488
Here is the query:
$query = "SELECT name,deleted,COUNT(message) as message FROM guestbook_message WHERE name='".$name."' AND deleted=1 GROUP BY name";
$result = mysql_query($query) or die(mysql_error());
$deletedtotal_row = mysql_fetch_array($result);
Here when I use it:
echo "You have had ".($deletedtotal_row['deleted']) ? $deletedtotal_row['deleted'] : '0'." messages deleted";
This errors, doesn't show an syntax error, but doesn't display any results.
But when I use:
echo ".$totaldeleted_row['deleted'].";
It works fine. But if there is no messages deleted for that user, it returns nothing, but I want it to display '0'.
Any ideas where I'm going wrong?
Upvotes: 0
Views: 815
Reputation: 433
use:
sprintf("You have had %d messages deleted", $deletedtotal_row['deleted');
Upvotes: 0
Reputation: 488
Thanks everybody. I got it working with:
echo "You have had ".($deletedtotal_row['deleted'] ? $deletedtotal_row['deleted'] : '0')." messages deleted";
Upvotes: 0
Reputation: 2891
if(mysql_num_rows($result)==0) {
echo 'no rows';
} else {
echo "You have had " . $deletedtotal_row['deleted'] ." messages deleted";
}
Upvotes: 0
Reputation: 4549
echo "You have had ".intval($deletedtotal_row['deleted'])." messages deleted";
Upvotes: 1
Reputation: 14135
change this:
echo "You have had ".($deletedtotal_row['deleted'] ? $deletedtotal_row['deleted'] : '0')." messages deleted";
Also, this echo ".$totaldeleted_row['deleted'].";
is very bad. Do this instead:
echo $totaldeleted_row['deleted'];
Upvotes: 0