View Full Version : Resolved Message Count?
liamallan
03-21-2010, 05:00 AM
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
djr33
03-21-2010, 05:16 AM
$q = mysql_query('SELECT * FROM `tablename`;');
echo mysql_num_rows($q);
liamallan
03-21-2010, 05:27 AM
it works, but counts all. say i (liamallan) logged in, i would want it to count my messages only.
something along the lines of:
$q = mysql_query('SELECT * FROM `messages` where username=reciever;');
echo mysql_num_rows($q);
djr33
03-21-2010, 05:36 AM
That syntax is correct, though it is more proper to use:
'........WHERE `username` = \''.$username.'\'';
Make sure $username is set to the current user.
liamallan
03-21-2010, 05:58 AM
just keep getting blank screen. here is what i got so far:
$q = mysql_query('SELECT * FROM `messages` WHERE `username` = \''.$username.'\'';
echo mysql_num_rows($q);
djr33
03-21-2010, 06:01 AM
Oh, just change `username` to `reciever`
(unrelated, but if you care, note that the correct spelling is receiver)
liamallan
03-21-2010, 06:18 AM
it works, thanx m8! but one more thing, i am having trouble inserting it alongside 'inbox' link:
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{
djr33
03-21-2010, 06:31 AM
."[<a href=\"inbox.php\">Inbox".mysql_num_rows($q)." </a>] <br>"
liamallan
03-21-2010, 06:43 AM
doesnt seem to be doing its thing, this wot i got:
."[<a href=\"inbox.php\">Inbox ".mysql_num_rows($q)."</a>] <br>"
djr33
03-21-2010, 08:12 AM
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).
liamallan
03-21-2010, 09:00 AM
that done the trick mate! thanks alot for ur time and knowledge
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.