I am thinking that I have not structured my database correctly!
I think you know it well. The country field should be stored in a related table. And a another database model (whould be )used to store user - country - score
first, lets create a form to get a user input, and build the entire part of your form...:
print "co name:<br> <input type=\"text\" name=\"co_name\"><br>";
Now, check if the user filled the co_name:
if ( !empty( $_POST["co_name"] ) )
{
......*1 lets build the sql query...*2 run the query.... *3 print the results .....
}
//1 An sql query looks like:
/* Change the table and field names if its needed!*/
$table="Users_table";
$SQL_QUERY = "co_name LIKE '%" . mysql_real_escape_string( $_POST["co_name"] ) . "%'";
$sql = " SELECT co_name , SUM(score_ref) AS score_refsum FROM $table
WHERE $SQL_QUERY
GROUP BY co_name ORDER BY score_refsum DESC";
// *2
mysql_query($sql) or die("Problem with the query: $sql" . mysql_error());
And when you print the results, you reach the countries and the summed scores:
// *3
if ( mysql_num_rows( $res ) > 0 )
{
while ( $one_row = mysql_fetch_object( $res ) )
{
print "<Co name>:$one_row->co_name<<br />";
print "<score>$one_row->score_refsum<br/>";
}
print "<hr>";
}
else
{
print "No CO found<br/>";
}
hello,jjozsi.