Jump to content

Count Array


avo

Recommended Posts

HI all

im sure thers is a simple answer for this one been trying to figure it out for a hour now but still can't find my answer

all it is im connecting to a db
grabbing info where the $_SESSION user is pressent to pull in all the id number information a
all i wish to do then is echo out how may id's i have pulled out of the db (in one number a count)

code i can get to work to echo out all the id's but i can not count them

ive been using count ()
my code is :

[code]mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db ($dbname) or die ( mysql_error ());
$query = "SELECT id FROM user_messages WHERE username= '".$_SESSION['user']."'";
$result = mysql_query ($query) or die ( mysql_error () );
while ( $x = mysql_fetch_array($result)) {
echo $x['id'];    
}[/code]

in place of echo $x['id'] ; i would just like to echo out the number of times id has been pulled from the db

thanks in advance
Link to comment
Share on other sites

[!--quoteo(post=377656:date=May 27 2006, 01:36 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ May 27 2006, 01:36 PM) [snapback]377656[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]$query = "SELECT COUNT(*) FROM user_messages WHERE username= '{$_SESSION['user']}' ";

$res = mysql_query($query);

$message_count = mysql_result($res, 0);[/code]
[/quote]
Yeah Barand's code is nice but if you want your query to return more than the count you would have to mess with GROUP BY and I don't like the idea of using it :P
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.