[eluser]Uriptical[/eluser]
Hi all,
In my model I have following function:
Code:
public function do_region_and_country_match($region_name, $country_name)
{
$query = "
SELECT COUNT( timezone_countries.name ) AS countries_in_region
FROM timezone_countries
JOIN timezone_regions ON timezone_regions.id = timezone_countries.timezone_region_id
WHERE (
timezone_regions.name = '" . $region_name . "'
)
AND (
timezone_countries.name = '" . $country_name . "'
)";
echo "the query is: " . $query . "<br /><br />";
$result_set = $this->db->query($query);
echo "number of rows = " . $result_set->num_rows() . "<br />";
foreach ($result_set->result() as $row)
{
if ($row->countries_in_region = 1) {
echo "countries_in_region = " . $row->countries_in_region . "</b>. region = " . $region_name . ". country = " . $country_name . "<br />";
return true;
}
else {
echo "countries_in_region = " . $row->countries_in_region . "</b>. region = " . $region_name . ". country = " . $country_name . "<br />";
return false;
}
}
}
It returns the following output:
Quote:the query is: SELECT COUNT( timezone_countries.name ) AS countries_in_region FROM timezone_countries JOIN timezone_regions ON timezone_regions.id = timezone_countries.timezone_region_id WHERE ( timezone_regions.name = 'Africa' ) AND ( timezone_countries.name = '' )
number of rows = 1
countries_in_region = 1. region = Africa. country =
The result, that being that the result is 1, is not correct. The correct result, however, is shown when I run the following query in phpMyAdmin:
Code:
SELECT COUNT( timezone_countries.name ) AS countries_in_region FROM timezone_countries JOIN timezone_regions ON timezone_regions.id = timezone_countries.timezone_region_id WHERE ( timezone_regions.name = 'Africa' ) AND ( timezone_countries.name = '' )
The result in phpMyAdmin is:
Quote:countries_in_region
0
Any ideas on what I've done wrong with the php code to get a result of 1 would be much appreciated.