Jump to content

[SOLVED] Count(*)


greens85

Recommended Posts

Hi,

 

Im currently in the process of building a jobs board, I want to count the number of people that have signed up for alerts by email. I have tried the following code but it just keeps returning 3 when the actual number is 7.

 

<?php
$alertcount = 'SELECT COUNT(*) AS count FROM resumes WHERE alertstatus IS NOT NULL GROUP BY alertstatus';
$alertresult = mysql_query ($alertcount) or die (mysql_error());
$alertrows = mysql_num_rows ($alertresult);
$alertrow = mysql_fetch_row ($alertresult);
?>
(<?php print "$alertrows"; ?>)

 

Can anybody see why this might be returning 3 opposed to 7?

Link to comment
Share on other sites

count 

24

6

 

Thats what it returns, im very limited in my php/mysql knowledge but i would guess whats why it is returning 3.

 

Do you have any idea how i need to change the query so that it counts the number of 'yes' in the alertstatus field?

Link to comment
Share on other sites

3 is number of result rows that query return

you have 3 diferent value in alertstatus field in database

try

<?php
$alertcount = 'SELECT COUNT(*) AS count, alertstatus FROM resumes WHERE alertstatus IS NOT NULL GROUP BY alertstatus';
$alertresult = mysql_query ($alertcount) or die (mysql_error());
$alertrows = mysql_num_rows ($alertresult);
while($alertrow = mysql_fetch_row ($alertresult)){
echo 'value: "', $alertrow['alertstatus'], '" is in database ', $alertrow['count'], " times.<br />\n";
}
?>

(not tested)

Link to comment
Share on other sites

I've solved this now, incase anyone needs it for future reference the code is:

 

<?php    
$x2 = "SELECT resumeid, COUNT(*) FROM resumes WHERE alertstatus = 'yes' GROUP BY resumeid";
$result2 = mysql_query($x2) or die(mysql_error());
$total_rows2 = mysql_num_rows($result2); 
$row2 = mysql_fetch_row($result2);  
?>
(<font color="#FF0000"><?php print "$total_rows2"; ?></font>)

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.