I'm able to pull the correct state from the field concatenation which reads: "City, State - Name County - zipcode" using the following code:
$sql="SELECT trim(substring(SUBSTRING_INDEX(county_city,',',-1),1,3)) as state
FROM
" . $this->table_name . "
WHERE
admid = 45";
If I use the following code to try and get a row count, it ends up being 0 rows found:
$sql="SELECT trim(substring(SUBSTRING_INDEX(county_city,',',-1),1,3)) as state,
COUNT(*) as total_rows
FROM
" . $this->table_name . "
WHERE
DATE_FORMAT(refer_date,'%m') = ?
AND
DATE_FORMAT(refer_date, '%Y') = ?
AND
unit = ?
AND
state = ?";
// prepare query statement
$stmt = $this->conn->prepare( $sql );
// bind variable values
$stmt->bindParam(1, $refer_month);
$stmt->bindParam(2, $refer_year);
$stmt->bindParam(3, $unit);
$stmt->bindParam(4, $state);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row['total_rows'];
Any idea why?