I have the following block of code which is expected to return the count
$sql = "SELECT sum(count) as count
FROM multipleowners WHERE owner = ? " . $localityquery;
$queryarray = array($owner, $locality);
$query = $this->db->query($sql, $queryarray);
if ($query->num_rows() > 0)
{
$result = $query->row_array();
$count = $result['count'];
}
But I am getting empty values when i try to print $count
.
I have used print_r($this->db->last_query());
and I got the following query,
SELECT sum(count) as count FROM multipleowners WHERE owner = 'Davenports Harbour Trustee (2012) Limited' and locality = 'Auckland Central'
When I executed this query directly onto my Postgresql
IDE
i got the output of count
as 2
.
What and where could this query be gone wrong ? I doubt the existence of (
and )
in the WHERE
clause. How do I fix this ?
Update
When I enabled the profiler I got the following query,
SELECT sum(count) as count
FROM multipleowners WHERE owner = 'Davenports Harbour Trustee (2012) Limited' and locality = 'Auckland Central'
So obviously the problem exists on the (
and )
!!
Bingo!! I have added the following line before I passed the variable $owner
to the query and it worked,
$owner = html_entity_decode($owner);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With