title: Retrieving data from two tables of mysql
body: <p>I Have Two Tables</p>
  
  <p>Table1</p>
  
  <pre><code> HTNO          SUBJECTCODE          INTERNALS          EXTERNALS            TOTAL
     1               s1                   20                  58                 78
     1               s2                   15                  20                 35
     1               s3                   10                  60                 70 
     2               s1                   10                  20                 30
     2               s2                   12                  30                 42
     2               s3                   15                  55                 70
     .
     .
     .
     so on up to N
  </code></pre>
  
  <p>Table 2</p>
  
  <pre><code>  SUBJECTCODE             SUBJECT NAME
         s1                    MATHS
         s2                   SCIENCE
         s3                    SOCIAL
  </code></pre>
  
  <p>I will be giving a form for student to enter the hallticket Number</p>
  
  <p>If student Enters 1 in form then the result should be</p>
  
  <pre><code>   Subjectcode        SubjectName        Internals       Externals        Total
         s1                Maths              20              58              78
         s2               Science             15              20              35
         s3                Social             10              60              70
  </code></pre>
  
  <p>The above should be the output</p>
  
  <p>But Here I am unable to retrieve SubjectName from Table2 in the result</p>
  
  <p>And here is my code which i am using </p>
  
  <pre><code>    &lt;?PHP
      $userInputEntities = htmlentities($userInput);
      echo $userInputEntities;
  
      $username = "admin";
      $password = "123456";
      $database = "test";
      $server = "localhost";
      $db = new PDO ("mysql:host=$server;dbname=$database", "$username", "$password");
  
      if ($db) {
      $id = $_GET['id'];
      $SQL = $db-&gt;prepare("SELECT * FROM Table1 WHERE htno = :id");
      $SQL -&gt; execute(array(':id'=&gt;$id));
      $n = $SQL-&gt;rowCount();
      echo "
      &lt;center&gt;&lt;table class='dynamic styled with-prev-next' data-table-tools='{'display':true}' align=center&gt;
      &lt;thead&gt;
      &lt;tr&gt;
      &lt;TH class='table-header dark' scope='col'&gt;SUBJECT CODE&lt;/TH&gt;
      &lt;TH class='table-header dark' scope='col'&gt;SUBJECT NAME&lt;/TH&gt;
      &lt;TH class='table-header dark' scope='col'&gt;INTERNALS&lt;/TH&gt;
      &lt;TH class='table-header dark' scope='col'&gt;EXTERNALS&lt;/TH&gt;
      &lt;TH class='table-header dark' scope='col'&gt;TOTAL&lt;/TH&gt;
  
      &lt;/tr&gt;&lt;/thead&gt;&lt;center&gt;";          
  
      while ($db_field = $SQL-&gt;fetch(PDO::FETCH_ASSOC)) {
  
  
      echo "&lt;tr&gt;&lt;tbody&gt;";
      echo "&lt;td align=center&gt;" . $db_field['SubjectCode'] . "&lt;/td&gt;";
  
       echo "&lt;td align=center&gt;" . $db_field['Internals'] . "&lt;/td&gt;";
     echo "&lt;td align=center&gt;" . $db_field['Externals'] . "&lt;/td&gt;";
     echo "&lt;td align=center&gt;" . $db_field['Total'] . "&lt;/td&gt;";
  
     echo "&lt;/tbody&gt;&lt;/tr&gt;";
  
     }
  </code></pre>
  
  <p>with this code i am unable to get SUbject Name for a particualr subject code of a student
  actually i have nt written any code to retrieve dubject name from Table2, I dont Know How to write it</p>
  
  <p>Please Help me</p>