problem with count and displaying result

Reply

Join Date: Nov 2008
Posts: 2
Reputation: castlelaker is an unknown quantity at this point 
Solved Threads: 0
castlelaker castlelaker is offline Offline
Newbie Poster

problem with count and displaying result

 
0
  #1
Nov 7th, 2008
Help
Spent HOURS on this and cannot see the problem.
It will display the country but not the number of clients that are within that country???
  1. <?php
  2.  
  3. //Retrieve the "count" for the number of people in the specified country
  4.  
  5. $country= $_POST['totalbycountry'];
  6.  
  7. //Connect to the server...$connect will contain the connection object
  8.  
  9. $connect = mysql_connect("localhost:3636", "root","");
  10.  
  11. //Connect to the relevant Database
  12.  
  13. $db=mysql_select_db("census",$connect);
  14.  
  15. //Set up the SQL statement in a variable with a WHERE clause
  16.  
  17. $query="SELECT count(*) FROM stats WHERE BirthCountry = country";
  18.  
  19. //Perform the SQL query against the database
  20.  
  21. $result=mysql_query($query);
  22.  
  23.  
  24. echo "The total number of people who were born in " .$country ;
  25.  
  26. ?>
Last edited by peter_budo; Nov 8th, 2008 at 6:58 pm. Reason: Correcting tags, please use [code] not <code>
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: problem with count and displaying result

 
0
  #2
Nov 8th, 2008
hello..see this:
  1. $query="SELECT count(*) as c FROM stats WHERE BirthCountry = country";
  2.  
  3. //Perform the SQL query against the database
  4.  
  5. $result=mysql_query($query);
  6. $row=mysql_fetch_array($result);
  7. echo $row['c'];
i don't know the query for counting no.of clients...but the above is the correct syntax...if this is not correct,post your table structure..
thank you.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: castlelaker is an unknown quantity at this point 
Solved Threads: 0
castlelaker castlelaker is offline Offline
Newbie Poster

Re: problem with count and displaying result

 
0
  #3
Nov 9th, 2008
Originally Posted by Shanti Chepuru View Post
hello..see this:
  1. $query="SELECT count(*) as c FROM stats WHERE BirthCountry ='country'";
  2.  
  3. //Perform the SQL query against the database
  4.  
  5. $result=mysql_query($query);
  6. $row=mysql_fetch_array($result);
  7. echo $row['c'];
i don't know the query for counting no.of clients...but the above is the correct syntax...if this is not correct,post your table structure..
thank you.
Thanks
This work fine if you put single quotes around 'country'.
If you dont no result is displayed
Thanks again
Castlelaker
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 24
Reputation: sasankasekhar is an unknown quantity at this point 
Solved Threads: 3
sasankasekhar's Avatar
sasankasekhar sasankasekhar is offline Offline
Newbie Poster

Re: problem with count and displaying result

 
0
  #4
Nov 11th, 2008
Originally Posted by castlelaker View Post
Thanks
This work fine if you put single quotes around 'country'.
If you dont no result is displayed
Thanks again
Castlelaker
This should be the correct statement I suppose:
  1. $query="SELECT count(*) FROM stats WHERE BirthCountry = ".$country." ;";

Regards.
Last edited by peter_budo; Nov 12th, 2008 at 5:22 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
IF SOMEONE FEELS THAT THEY HAD NEVER MADE A MISTAKE IN THEIR LIFE, THEN  IT MEANS THEY HAD NEVER TRIED A NEW THING IN THEIR LIFE
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: jyothi chundi is an unknown quantity at this point 
Solved Threads: 0
jyothi chundi jyothi chundi is offline Offline
Newbie Poster

Re: problem with count and displaying result

 
0
  #5
Nov 11th, 2008
  1.  
  2. $query="SELECT count(*) as c FROM stats WHERE BirthCountry ='$country'";
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC