Jump to content

How do I do this - Adding up all unread's and echo it out in a number


TeddyKiller

Recommended Posts

Simple PHP Query to get what is needed.

$query = mysql_query("select * from `sent_messages` where `status`='unread' and `to_id`='$user->id'");

This is the query to get the data. I'm just needing to bring out all the rows into a number.

If there are 5 rows, so 5 mails unread. It'll echo out.. 5.

 

This is probably using a foreach, but I'm not sure?

 

Hope you can help!

P.S Sorry I'm posting alot recently. I'm working more than usual and running into the basics all over again..

If you *just* need the number or rows (but not the actual info in the rows themselves) you should use:

 

SELECT COUNT(*) FROM sent_messages WHERE status = 'unread' AND to_id = '$user->id'

 

If you need the info in the rows too, your current query will work, you just need to use mysql_num_rows($query) to get the number of results.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.