以下是查询:
$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);
我在这里使用它:
echo "You have had ".($deletedtotal_row['deleted']) ? $deletedtotal_row['deleted'] : '0'." messages deleted";
此错误,不显示语法错误,但不显示任何结果。
但是当我使用时:
echo ".$totaldeleted_row['deleted'].";
工作正常。但是如果没有为该用户删除消息,则它不返回任何内容,但我希望它显示为“0”。
我出错的任何想法?
答案 0 :(得分:1)
echo "You have had ".intval($deletedtotal_row['deleted'])." messages deleted";
答案 1 :(得分:0)
改变这个:
echo "You have had ".($deletedtotal_row['deleted'] ? $deletedtotal_row['deleted'] : '0')." messages deleted";
此外,echo ".$totaldeleted_row['deleted'].";
非常糟糕。这样做:
echo $totaldeleted_row['deleted'];
答案 2 :(得分:0)
if(mysql_num_rows($result)==0) {
echo 'no rows';
} else {
echo "You have had " . $deletedtotal_row['deleted'] ." messages deleted";
}
答案 3 :(得分:0)
谢谢大家。我得到了它:
echo "You have had ".($deletedtotal_row['deleted'] ? $deletedtotal_row['deleted'] : '0')." messages deleted";
答案 4 :(得分:0)
使用:
sprintf("You have had %d messages deleted", $deletedtotal_row['deleted');