Jump to content

[SOLVED] Counting the number of messages a user has and displaying the number!


andrew_biggart

Recommended Posts

Im trying to count the numbe of messages a user has and i can get it to count all the messages but when i try and add the where statement it doesnt display the number grrrrr.

 

Im using the follwoing code.

 

<?php

   include("config_contact.php");
   $username=$_SESSION['myusername'];
             
   // Retrieve data from database 
   $sql = "SELECT count(Message_user) as mescount WHERE Message_user=$username FROM User_messagesT ";
   $result = mysql_query($sql);

   $row = mysql_fetch_assoc($result);

   echo $row['mescount'];
?>

Link to comment
Share on other sites

is this right now? quotes on which query?

 

<?php

   include("config_contact.php");
   $username=$_SESSION['myusername'];
             
   // Retrieve data from database 
   $sql = "SELECT count(Message_user) as mescount FROM User_messagesT WHERE Message_user=$username ";
   $result = mysql_query($sql);

   $row = mysql_fetch_assoc($result);

   echo $row['mescount'];
?>

Link to comment
Share on other sites

one last thing sorry im trying to get the number to be displayed in brackets ie messages (5) nd when i try and put the brackets in the echo is fucks up so ive done it this way. With them before and after the php. But the problem is they show up even if there is no messages so how do i dd them to the echo successfully so they only show up when there is a number to display?

 

(<?php

   include("config_contact.php");
   $username=$_SESSION['myusername'];
             
   // Retrieve data from database 
   $sql = "SELECT count(Message_user) as mescount FROM User_messagesT WHERE Message_user='$username' ";
   $result = mysql_query($sql);

   $row = mysql_fetch_assoc($result);

   echo $row['mescount'];
?>)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.