943,535 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 642
  • PHP RSS
Nov 7th, 2008
0

problem with count and displaying result

Expand Post »
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???
php Syntax (Toggle Plain Text)
  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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
castlelaker is offline Offline
2 posts
since Nov 2008
Nov 8th, 2008
0

Re: problem with count and displaying result

hello..see this:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Nov 9th, 2008
0

Re: problem with count and displaying result

hello..see this:
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
castlelaker is offline Offline
2 posts
since Nov 2008
Nov 11th, 2008
0

Re: problem with count and displaying result

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:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sasankasekhar is offline Offline
24 posts
since Jan 2007
Nov 11th, 2008
0

Re: problem with count and displaying result

PHP Syntax (Toggle Plain Text)
  1.  
  2. $query="SELECT count(*) as c FROM stats WHERE BirthCountry ='$country'";
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyothi chundi is offline Offline
2 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: anti spam contact form
Next Thread in PHP Forum Timeline: Semi-automated email script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC