如果计数> 0不工作。如果有要读取的新消息,请尝试以不同方式设置URL以显示。 [英] if count > 0 isnt working. Trying to set a URL differently to display if there is a new message to be read.

查看:86
本文介绍了如果计数> 0不工作。如果有要读取的新消息,请尝试以不同方式设置URL以显示。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图让我的消息链接显示是否有当前登录会话的用户有新消息。 />


在消息数据库表中,0未读并且读取1,因此应返回任何未读并发送到会话用户名的消息。目前,没有返回任何行(因为所有消息都被读取(或1)),因此链接不应显示(新)部分,但确实如此。我将计数($ success)更改为> 1执行了其他代码。



这是我的代码:



Hi,

Im trying to get my messages link to show if there is a new message to the user that is currently signed in to the session.

In the messages database table, 0 is unread and 1 is read so any messages that are unread and sent to the session username should be returned. Currently, there are no rows being returned (because all messages are read (or 1)) so the link should not show the '(new)' part but it does. I changed the count($success) to > 1 and the code in the else was executed.

Here is my code:

$s_username = $_SESSION['username'];

$db = Database::getConnection();
				$query = 'SELECT * FROM messages WHERE messageTo = :to AND messageRead = 0';
				$output = $db->prepare($query);
				$output->bindParam(':to', $s_username);
				$success = $output->execute();
					if (count($success) > 0){
						$msg = '<li><a href="messages.php">My Messages (new)</a></li>';
					} else {
						$msg = '<li><a href="messages.php">My Messages</a></li>';
					}
				echo $msg;





我错过了一些明显的东西吗?我明白,如果没有行,那么它确实= 0因为它是空的,但是如果它大于并且有未读消息给会话用户,它应该可以工作,对吗?



Am I missing something obvious? I understand that if there are no rows then it does = 0 because its empty, but if it is greater than and there are unread messages to the session user, it should work, right?

推荐答案

success)to> 1执行了其他代码。



这是我的代码:



success) to > 1 and the code in the else was executed.

Here is my code:


s_username =
s_username =


_SESSION [' username'];

_SESSION['username'];


这篇关于如果计数&gt; 0不工作。如果有要读取的新消息,请尝试以不同方式设置URL以显示。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆