Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Message Count?

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Question 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
    Last edited by liamallan; 03-21-2010 at 09:13 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $q = mysql_query('SELECT * FROM `tablename`;');
    echo mysql_num_rows($q);
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    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); 

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That syntax is correct, though it is more proper to use:
    '........WHERE `username` = \''.$username.'\'';

    Make sure $username is set to the current user.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    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); 

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Oh, just change `username` to `reciever`

    (unrelated, but if you care, note that the correct spelling is receiver)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    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{ 

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    ."[<a href=\"inbox.php\">Inbox".mysql_num_rows($q)." </a>] <br>"
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    doesnt seem to be doing its thing, this wot i got:
    PHP Code:
    ."[<a href=\"inbox.php\">Inbox ".mysql_num_rows($q)."</a>] <br>" 
    Last edited by liamallan; 03-21-2010 at 06:58 AM.

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •