title: Access table data when using PHP and MySQL
body: <p>Okay, I can post the PHP code if needed but I'm trying to use some data in my database, but have no idea how I can access it. It might be an easy reply but I'm new to this game...</p>
  
  <p>Basically, I have been able to set up a login system for my site, where if you log in, it will display the logged in user's username, this is done through the use of $_SESSION and a session class.</p>
  
  <p>Where if the user is logged in ($session->logged_in) etc</p>
  
  <pre><code>        &lt;h3&gt;Welcome &lt;? echo $session-&gt;username?&gt; &lt;/h3&gt;
          &lt;/head&gt;
  
                  &lt;body&gt;
        &lt;p&gt; Welcome to the website, your details are below &lt;/p&gt;
  
          &lt;/body&gt;
          &lt;?php } ?&gt;
  </code></pre>
  
  <p>I return the user's username as such. </p>
  
  <p>However, I can only currently access data from the table 'users', and 'users' is connected through foreign keys to a table called 'passengers' through the 'username' field.</p>
  
  <p>What I would like to do, is instead of printing the username, print the user's surname.</p>
  
  <p>So essentially it is like:-</p>
  
  <p>Logging in sets up a session and recognises the username that is logged in.
  By querying this username in a different table, can pull up data from all corresponding tables in the database.</p>
  
  <p>But I have no idea how to go about it..</p>
  
  <p>If you guys and girls know of any sample code, or could point me in the right direction that'd be fantastic.</p>