I am trying to track dynamic php names depending on the page id for seo purposes.
First of all, all of my pages include header.php
And this is how mine begins header.php:
include("database.php");
if (isset($_GET["category_id"])) {
$query = $handler->query("SELECT * FROM categories WHERE category_id = ".$_GET['category_id']." ");
while($r = $query->fetch()) {
$title = $r["title"];
}
}
if (isset($_GET["article_id"])) {
$query = $handler->query("SELECT * FROM articles WHERE article_id = ".$_GET['article_id']." ");
while($r = $query->fetch()) {
$title = $r["title"];
}
}
if (isset($_GET["user_id"])) {
$query = $handler->query("SELECT * FROM users WHERE user_id = ".$_GET['user_id']." ");
while($r = $query->fetch()) {
$title = $r["username"];
}
}
And after I feel free to repeat the title as shown below:
<title><?php if (isset($_GET["category_id"])) { echo $title; echo " |"; }
if (isset($_GET["article_id"])) { echo $title; echo " |"; }
if (isset($_GET["user_id"])) { echo $title; echo " |"; } ?> mypage.com</title>
*
This is the result:
on Page category.php?category_id=1title: "Category 1 | mypage.com"
on Page article.php?article_id=1title: "Article 1 | mypage.com"
on Page users.php?user_id=1title: "Username 1 | mypage.com"
*
My question is: I wonder if I can load a database with this structure?
When I'm on users.php?user_id=1, is php still executing this code ?:
if (isset($_GET["category_id"])) {
$query = $handler->query("SELECT * FROM categories WHERE category_id = ".$_GET['category_id']." ");
while($r = $query->fetch()) {
$title = $r["title"];
}
}
- , if (isset($_GET["category_id"])) { , ?