我想为我的社区网站建立通报制度,我试图用一个while
循环来获取数据,当曾经在一个条件if语句内得到满足while循环,它应该显示/打印数据到页面。出于某种原因,它只显示一个结果,不知道为什么。if和else if while循环中的语句不能正常工作
我的数据库的结构:
CREATE TABLE IF NOT EXISTS `notifications` (
`notification_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`to_id` int(11) NOT NULL,
`notification_identifier` enum('1','2','3','4','5','6') NOT NULL,
`notify_id` int(11) NOT NULL,
`opened` enum('0','1') NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`notification_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
的notification_identifier告诉我它是什么类型的通知(例如轮廓评论,状态更新,喜欢)和notify_id
告诉我,每一个具体的表,我需要的ID检查。
我的代码:
<?
$DisplayNotification ="";
$unread = "0";
$mynotify = mysql_query("SELECT * FROM notifications WHERE to_id='$logOptions_id' AND opened='$unread'") or die (mysql_error());
$notify_Count = mysql_num_rows($mynotify);
if($notify_Count>0){
while($row = mysql_fetch_array($mynotify)){
$notification_id = $row["notification_id"];
$memb_id = $row["user_id"];
$identifier = $row["notification_identifier"];
$notify_id =$row["notify_id"];
$timestamp = $row["timestamp"];
$convertedTime = ($myObject -> convert_datetime($timestamp));
$when_notify = ($myObject -> makeAgo($convertedTime));
if($identifier == 1){// condition 1
$DisplayNotification ='user added you as a friend';
}else if ($identifier == 2) {//condition 2
$DisplayNotification ='user commented on your post';
}
}
}else{// End of $notify
$DisplayNotification ='You have no new notifications.';
}
?>
任何帮助赞赏
谢谢,这么多的固定它现在使用的$ DisplayNotification =“用户添加你为好友\ n”;和它的工作就像一个魅力笑 – user1509217 2012-07-07 20:51:37
我很高兴,这是有帮助的。如果此答案解决了您的问题,请点击左侧的复选标记。 – VoteyDisciple 2012-07-08 02:52:50