A link will be index.php?page=PAGENAME. The PAGENAME is mostly stored in the database, but some are static. I want an if/else statement to echo the title. The static part is not so hard.
function current_page() {
$uri = $_SERVER["REQUEST_URI"];
$goal = explode("?page=", $uri);
$keyone = $goal[1];
return $keyone;
}
This will only show what comes after ?page= so I have the pagename. Some static pages are dashboard and settings. The following if statement is used to show the title of the static pages:
$current = current_page();
if ($current == 'dashboard') {
echo 'Dashboard';
}
elseif ($current == 'settings') {
echo 'Settings';
}
Now the part I can't seem to get to work is that for every country stored in the database there should be an elseif statement. The PAGENAME is the country iso code which is stored in the database (as countryISO). But when making an database connection in the if if/else statement an error occur saying unexpected 'elseif'.
I'm trying to create a foreach for every row in the database with the data.
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$sql = "SELECT * FROM countries";
$result = $conn->query($sql);
while($row = mysqli_fetch_assoc($result)) {
$iso = $row['countryISO'];
elseif ($current == $iso) {
echo $row['countryname'];
}
}
$conn->close();
Aucun commentaire:
Enregistrer un commentaire