title: Get data using variable from query string?
body: <p>I hope the title I used here was understandable...</p>
  
  <p>I have a database with two columns: ward_id and ward_name.</p>
  
  <p>I wish to create dynamic pages for each ward and have the ward_name show in the page title. I have created a header.php file which I am including.</p>
  
  <p>I am passing the id through the URL using ....?wid={$row['ward_id']} which is working fine when I create other queries that use that id to get data from the database.</p>
  
  <p>However the problem I am having is that the page refuses to display the ward_name as the page title. I expected something like this to work:</p>
  
  <pre><code>    $wardid = $_GET['wid'];
  
      $query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
      $result = mysql_query($query);
  
      while ($row=mysql_fetch_array($result))
      {
  $pagetitle = "$row['ward_name']";
      }
  </code></pre>
  
  <p>But it doesn't, I have tried so many variations on the above I can't possibly remember them all now so I really hope someone can help me... Here is the code as it currently stands:</p>
  
  <p>Header Page:</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
      &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;&lt;?php echo $pagetitle; ?&gt;&lt;/title&gt;
      &lt;link rel="stylesheet" href="style.css"&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
  
          &lt;div class="wholepage"&gt;
  
              &lt;div class="headlinewrapper"&gt;
                  &lt;div class="headline"&gt;
                      &lt;h1&gt;&lt;/h1&gt;
                      &lt;h2&gt;&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="headlinesidewrapper"&gt;
                  &lt;div class="headlineside"&gt;
                      &lt;p&gt;shv jsfj sjnsf jnsf nsnf nj njsfn
  njfjn sfns njf njnsf njs dgbjn dn jnd njjn dd d d nj njd njnd njd nn djndj njd&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="topnavigation"&gt;
                  &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="boroughs.php"&gt;Boroughs&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="wards.php"&gt;Wards&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
  
              &lt;div class="sidebar"&gt;
  
              &lt;/div&gt;
  
              &lt;div class="mainpagewrapper"&gt;
  </code></pre>
  
  <p>Dynamic page:</p>
  
  <pre><code>&lt;?php
  
      $pagetitle = "Hello";
      include ('header.php');
  
      ?&gt;
  
                  &lt;div class="mainpage"&gt;
                      &lt;div class="infobox"&gt;
  
                      &lt;/div&gt;
      &lt;?php
  
      require('mysqli_connect.php');
  
      mysql_select_db('onetwom2_london');
  
  
      $wardid = $_GET['wid'];
  
      $query = "SELECT ward_name, ward_id FROM wards WHERE ward_id=$wardid";
      $result = mysql_query($query);
  
      while ($row=mysql_fetch_array($result))
      {
      echo "&lt;div class=\"boroughlist\"&gt;&lt;p&gt;{$row['ward_name']}&lt;/p&gt;&lt;/div&gt;" ;
      }
  
      $pagetitle = $result;
  
      ?&gt;
  
      &lt;div class="clear"&gt;
      &lt;/div&gt;      
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
      &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>So I just want to know how/if it is possible to match the id passed through the URL to the ward_id stored on the database and then have the page title display the ward_name linked to that id. I apologise if this is a really easy question, I have spent hours trying to work this out and I am completely stumped! (the code I posted above is just the end result of 5 hours of frustration so please appreciate I have tried hard before asking you for help :) )</p>