title: dynamic php title depends on page id and using of "if (isset"
body: <p>I'm trying to echo out dynamic php titles depends on page id for seo purposes.</p>
  
  <p>First of all, all of my pages includes <code>header.php</code></p>
  
  <p>And this is how my <code>header.php</code> begins like:</p>
  
  <pre><code>include("database.php");
  
  //connect tables in order to echo out titles
  
  //1- connect to categories table if isset get category_id
  if (isset($_GET["category_id"])) {
  $query = $handler-&gt;query("SELECT * FROM categories WHERE category_id = ".$_GET['category_id']." ");
  while($r = $query-&gt;fetch()) {
    $title = $r["title"];
  
    }
  }
  
  //2- connect to articles table if isset get article_id
  if (isset($_GET["article_id"])) {
  $query = $handler-&gt;query("SELECT * FROM articles WHERE article_id = ".$_GET['article_id']." ");
  while($r = $query-&gt;fetch()) {
    $title = $r["title"];
  
    }
  }
  
  //3- connect to users table if isset get user_id
  if (isset($_GET["user_id"])) {
  $query = $handler-&gt;query("SELECT * FROM users WHERE user_id = ".$_GET['user_id']." ");
  while($r = $query-&gt;fetch()) {
    $title = $r["username"];
  
    }
  }
  </code></pre>
  
  <p>And after I feel free to echo out title like below:</p>
  
  <pre><code> &lt;title&gt;&lt;?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 " |"; } ?&gt; mypage.com&lt;/title&gt;
  </code></pre>
  
  <p>*</p>
  
  <p>This is result:</p>
  
  <p>on <code>category.php?category_id=1</code> Page title is: "Category 1 | mypage.com"</p>
  
  <p>on <code>article.php?article_id=1</code> Page title is: "Article 1 | mypage.com"</p>
  
  <p>on <code>users.php?user_id=1</code> Page title is: "Username 1 | mypage.com"</p>
  
  <p>*</p>
  
  <p>My question is, I am wondering if I over load the database with this structure?</p>
  
  <p>When I'm on <code>users.php?user_id=1</code> is php still execute this code?:</p>
  
  <pre><code>//1- connect to categories table if isset get category_id
  if (isset($_GET["category_id"])) {
  $query = $handler-&gt;query("SELECT * FROM categories WHERE category_id = ".$_GET['category_id']." ");
  while($r = $query-&gt;fetch()) {
    $title = $r["title"];
  
    }
  }
  </code></pre>
  
  <p>or because of I'm using <code>if (isset($_GET["category_id"])) {</code> on the begining I'm not connecting to database and there is no over load to database?</p>