title: Using JOIN to display data in a table
body: <p>Thanks for reading my question</p>
  
  <p>i am trying to make *clients_id* from the table <strong>repair_jobs</strong> appear as the <em>name</em> from the table <strong>contacts</strong></p>
  
  <p>but i am having no luck
  i have got 2 sql query's is this wrong?</p>
  
  <p>the 1st</p>
  
  <pre><code>$query = "select * from repair_jobs";
  </code></pre>
  
  <p>this helps me display the information i need regarding the fields from repair_jobs and works</p>
  
  <p>this is the 2nd</p>
  
  <pre><code>$query = "SELECT repair_jobs.client_id, contacts.name
  FROM repair_jobs
  INNER JOIN contacts
  ON repair_jobs.client_id=contacts.name";
  </code></pre>
  
  <p>under that i have this to try to display the name of the client</p>
  
  <pre><code>echo "&lt;td&gt;{$client_id}&lt;/td&gt;";
  </code></pre>
  
  <p>but it is only displaying the number and not the data (clients name) that i need</p>
  
  <p>am i missing something?</p>
  
  <hr>
  
  <h2>Additional information</h2>
  
  <p>The client_id (repair_jobs) is a number and is the same as id (contacts) but wanting to display the name (contacts)</p>
  
  <p><strong>CLIENTS</strong></p>
  
  <pre><code>Id – name – surname – phone – address
  </code></pre>
  
  <p><strong>REPAIRS</strong></p>
  
  <pre><code>Id – clients_id (same as id in clients) – unit – date – price
  </code></pre>
  
  <hr>
  
  <h2>current code</h2>
  
  <pre><code>&lt;?php
  //include database connection
  include 'db_connect.php';
  
  //query all records from the database
  $query = "select * from repair_jobs";
  
  //execute the query
  $result = $mysqli-&gt;query( $query );
  
  //get number of rows returned
  $num_results = $result-&gt;num_rows;
  
  //this will link us to our add.php to create new record
  if( $num_results &gt; 0){ //it means there's already a database record
  
      //start table
      //creating our table heading
      echo " &lt;table class='table_basic'&gt;";
      echo "&lt;thead&gt;&lt;tr&gt;";
          echo "&lt;th&gt;Job #&lt;/th&gt;";
          echo "&lt;th&gt;Name Of Unit&lt;/th&gt;";
          echo "&lt;th&gt;Client&lt;/th&gt;";
          echo "&lt;th&gt;Estimated Value&lt;/th&gt;";
      echo "&lt;/thead&gt;&lt;/tr&gt;&lt;tbody&gt;&lt;tr&gt;";
  
      //loop to show each records
      while( $row = $result-&gt;fetch_assoc() ){
              //extract row
              //this will make $row['firstname'] to
              //just $firstname only
              extract($row);
  
              //creating new table row per record
              echo "&lt;tr&gt;";
                  echo "&lt;td width='40px'&gt;&lt;a href='rdetails.php?id={$id}'&gt;# {$id}&lt;/a&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;{$rmake} {$rmodel}&lt;/td&gt;";
  
  $query = "SELECT rj.client_id, c.name AS client_name FROM repair_jobs rj INNER JOIN contacts c ON rj.client_id=c.id";
  echo "&lt;td&gt;{$client_name}&lt;/td&gt;";
  
  echo '&lt;td align="center"&gt;&lt;span class="badge badge-success"&gt;£';
  $lhours = $labour;
  $repaircosts = $ourcosts;
  $labourpay = $labourcharge;
  $sum_total = $repaircosts +($lhours * $labourpay);
  
  
  
  
  print ($sum_total);
  echo '&lt;/span&gt;&lt;/td&gt;';
  echo "&lt;/td&gt;";
  echo "";
      }
  
      echo "&lt;/tr&gt;&lt;/table&gt;";//end table
  
  }else{
      //if database table is empty
      echo "No records found.";
  }
  
  //disconnect from database
  $result-&gt;free();
  $mysqli-&gt;close();
  
  ?&gt;
  </code></pre>