My goal is to get the country names to print out in alphabetical order. This is the function I wrote for that...
function getCountries(){
$namesQ = 'SELECT Name FROM `country` ORDER BY Name ASC';
global $myPdo;
$command = $myPdo -> prepare('namesQ');
$command -> execute();
return $command;
}
Then, I echo out the names from an array in HTML...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Country Names</title>
<link type="text/css" rel="stylesheet" href="primary.css" />
</head>
<body>
<div id="main" action="controller.php" method="post">
<?php
$countries = getCountries();
$countryNames = $countries->fetchAll();
foreach( $countryNames as $countryName )
{
echo 'test';
echo '<p> ' . $countryName['Name'] . '</p>';
}
?>
</div>
</body>
</html>
But it seems that the foreach
loop does not get accessed at all, because even...
echo 'test';
... does not print to screen.
I changed the index in $countryName
to fhsdjk
since there is no such index, but I don't even get an error message or anything at all. How can I get it to echo
out whatever is inside the foreach
loop?