Could you help help me correct the follow piece of code
I am getting the following error.
"The website encountered an unexpected error. Please try again later."
public function __construct(Connection $connection) {
$this->connection = Database::getConnection();
}
public function hello($state = '0') {
$sqlQuery = $connection->select('pop11', 'C2011')
->fields('C2011', array('male', 'female'))
->condition('C2011.sCode', '10', '=');
$data = $sqlQuery->execute();
if ($data) {
$results = $data->fetchAll(\PDO::FETCH_OBJ);
foreach ($results as $row) {
echo "Field a: {$row->male}, field b: {$row->female}";
}
}else{
return array('#title' => 'Error', '#markup' => 'Could not Find. What you are Looking for.',);
}
}