954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem with count and displaying result

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

//Retrieve the "count" for the number of people in the specified country

$country= $_POST['totalbycountry'];

//Connect to the server...$connect will contain the connection object

$connect = mysql_connect("localhost:3636", "root","");

//Connect to the relevant Database

$db=mysql_select_db("census",$connect);

//Set up the SQL statement in a variable with a WHERE clause

$query="SELECT count(*) FROM stats WHERE BirthCountry = country";

//Perform the SQL query against the database

$result=mysql_query($query);


echo "The total number of people who were born in " .$country ;

?>
castlelaker
Newbie Poster
2 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

hello..see this:

$query="SELECT count(*) as c FROM stats WHERE BirthCountry = country";

//Perform the SQL query against the database

$result=mysql_query($query);
$row=mysql_fetch_array($result);
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.

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hello..see this:

$query="SELECT count(*) as c FROM stats WHERE BirthCountry ='country'";

//Perform the SQL query against the database

$result=mysql_query($query);
$row=mysql_fetch_array($result);
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

castlelaker
Newbie Poster
2 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 
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:

$query="SELECT count(*) FROM stats WHERE BirthCountry = ".$country." ;";


Regards.

sasankasekhar
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 4
 
$query="SELECT count(*) as c FROM stats WHERE BirthCountry ='$country'";
jyothi chundi
Newbie Poster
2 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You