title: Something is wrong with database display data clientside
body: <p>I'm building this CRM and I'm running into a bit of a weird situation when writing a query to display tables data client-side. I have hard time understanding how to fix it... I did delete a foreign key in a different table prior to encountering this issue because I wanted to modify the primary row and now I guess im paying the price I don't know what to do... Client-side how the data display is really not matching whats in database... Anyways i'm ready to get eaten alive... I'm a NOOB i'm learning the hard way and I also write PHP like im a noob so my code does look noobish but it works for me and that's how I understand it. So If you have any tips how to fix this that'd be great... </p>
  
  <p>The problem is the following : The ID row client-side does not return the one in the database and the names who the message was sent to is not matching the ones in the database. I suspect it has something to do with the id from which I deleted the foreign key...</p>
  
  <p><strong>database side | sentmessages table</strong>
  <a href="https://i.stack.imgur.com/KyNDn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KyNDn.png" alt="enter image description here"></a></p>
  
  <p><strong>client-side</strong></p>
  
  <p><a href="https://i.stack.imgur.com/oPePE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oPePE.png" alt="enter image description here"></a></p>
  
  <p><strong>mailmessages.php</strong></p>
  
  <pre><code> &lt;!-- 
  ================================================================
  Sent Messages 
  ================================================================
  --&gt;
  &lt;?php
  
  $perpage=5;
  if(isset($_GET['page'])){
      $page=$_GET['page'];
  }
  else{
      $page=1;
  }  
  
  
  
  $offset=($page-1)*$perpage;
  $sqlsent="SELECT * FROM sentmessages INNER JOIN employees ON sentmessages.toEmployee_id=employees.employee_id WHERE username = '$user_check' LIMIT ".$offset.",".$perpage."";
  $resultsent=mysqli_query($db,$sqlsent);
  ?&gt;
         &lt;table id="table" class="sortable rwd-table table table-striped table-hover tablesorter " &gt;
  
        &lt;thead style="cursor:pointer;"&gt;
            &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Date Sent&lt;/th&gt;
            &lt;th&gt;To&lt;/th&gt;
          &lt;th&gt;Subject&lt;/th&gt;
              &lt;th style='visibility: hidden;'&gt;Message&lt;/th&gt;
       &lt;/thead&gt;
  
       &lt;tbody&gt;
      &lt;?php while ($sent = mysqli_fetch_assoc($resultsent)) {?&gt;
        &lt;tr&gt;
             &lt;td data-th="ID"&gt;&lt;?=$sent['id'];?&gt;&lt;/td&gt;
                &lt;td data-th="Date Sent"&gt;&lt;?=$sent['time'];?&gt;&lt;/td&gt;
  
                &lt;?php $toEmployee_idfnln ="SELECT first_name, last_name FROM employees INNER JOIN sentmessages ON employees.employee_id=sentmessages.toEmployee_id WHERE username=employees.username";$resulfnln=mysqli_query($db,$toEmployee_idfnln);$displaynames = $resulfnln-&gt;fetch_assoc();?&gt;
          &lt;td data-th="To"&gt;&lt;?=$displaynames['first_name'];?&gt; &lt;?=$displaynames['last_name'];?&gt;&lt;/td&gt;
  
          &lt;td data-th="Subject"&gt;&lt;?=$sent['subject'];?&gt;&lt;/td&gt;
          &lt;td data-th="Message"&gt;&lt;i class="fa fa-eye optionbox" aria-hidden="true"&gt;&lt;/i&gt; &lt;i class="fa fa-trash optionbox" aria-hidden="true"&gt;&lt;/i&gt;&lt;/td&gt;
        &lt;/tr&gt;
          &lt;?php };?&gt;
       &lt;/tbody&gt;
       &lt;tfoot&gt;&lt;/tfoot&gt;
  
  
      &lt;/table&gt;
  
  
             &lt;div class='col-md-6 pull-left'&gt;
                 &lt;p&gt;Total : 
                     &lt;?php $sqlsentmsg="SELECT * FROM sentmessages INNER JOIN employees ON sentmessages.toEmployee_id=employees.employee_id WHERE username = '$user_check'"; $resultsentmsg=mysqli_query($db,$sqlsentmsg); $rowcountmsg=mysqli_num_rows($resultsentmsg);echo $rowcountmsg;?&gt;
  
                      Sent Messages&lt;/p&gt;
  
              &lt;/div&gt;
  </code></pre>