-
Message Count?
hi, im trying to integrate a private messaging system onto my site. my aim is to try gain info from the 'messages' database which looks like this:
id......reciever.............sender.........subject............message..........recieved
32.....lianesherry..........liamallan.......READ!!!............hi......................1
33.....HansBoatman1.....liamallan.......hey!................just testing.........0
35.....liamallan.............lianesherry....kghj................jhgfj...................0
42.....HansBoatman1.....liamallan.......gfhfghfg..........fghghhjfdh...........0
i want to disply amount of messages each user has beside a link to their inbox eg. [Inbox(3)]. any ideas on how i could do this? if u need anymore info, just ask. thanx
-
$q = mysql_query('SELECT * FROM `tablename`;');
echo mysql_num_rows($q);
-
it works, but counts all. say i (liamallan) logged in, i would want it to count my messages only.
something along the lines of:
PHP Code:
$q = mysql_query('SELECT * FROM `messages` where username=reciever;');
echo mysql_num_rows($q);
-
That syntax is correct, though it is more proper to use:
'........WHERE `username` = \''.$username.'\'';
Make sure $username is set to the current user.
-
just keep getting blank screen. here is what i got so far:
PHP Code:
$q = mysql_query('SELECT * FROM `messages` WHERE `username` = \''.$username.'\'';
echo mysql_num_rows($q);
-
Oh, just change `username` to `reciever`
(unrelated, but if you care, note that the correct spelling is receiver)
-
it works, thanx m8! but one more thing, i am having trouble inserting it alongside 'inbox' link:
PHP Code:
if($session->logged_in){
echo "Welcome <b>$session->username</b>! <br><br>"
."*[<a href=\"comments.php\">Feedback</a>]* <br><br>"
."[<a href=\"inbox.php\">Inbox(echo mysql_num_rows($q);) </a>] <br>"
."[<a href=\"onlineusers.php\">Whos Online?</a>] <br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] <br>"
."[<a href=\"useredit.php\">Edit Account</a>] <br>";
if($session->isAdmin()){
echo "[<a href=\"admin/admin.php\">Admin Center</a>] <br><br>";
}
echo "[<a href=\"process.php\">Logout</a>]";
}
else{
-
."[<a href=\"inbox.php\">Inbox".mysql_num_rows($q)." </a>] <br>"
-
doesnt seem to be doing its thing, this wot i got:
PHP Code:
."[<a href=\"inbox.php\">Inbox ".mysql_num_rows($q)."</a>] <br>"
-
That is correct. Be sure that $q has the right variable scope: try putting the query line right above the beginning of that code (all of what you posted above for the output).
-
that done the trick mate! thanks alot for ur time and knowledge