title: Compare rows in PHP
body: <p>Hi I would like to compare two tables from two different databases. </p>
  
  <p>Select from the <strong>first database</strong></p>
  
  <pre><code>$sql= mysqli_query ("SELECT * FROM emasa.staff_detail");
  $row = mysqli_fetch_array($sql);
  </code></pre>
  
  <p>Select from the <strong>second database</strong></p>
  
  <pre><code>$sql2 = mysqli_query ("SELECT * FROM employee");
  $row2 = mysqli_fetch_array($sql2);
  </code></pre>
  
  <p>Then I compare the two table</p>
  
  <pre><code>if ($row['icnum'] == $row2['emp_ic'])
  { 
       echo "Data already exist in both database.";
  }
  
  else
  {
        while ($row = mysqli_fetch_assoc($sql))
        {
           echo "&lt;td align='center' height='30'&gt;" . $row ['name'] . "&lt;/td&gt;";
           echo "&lt;td align='center'&gt;" .$row['icnum'] . "&lt;/td&gt;";
        }
  }
  </code></pre>
  
  <p>But my problem is it only compares the first row in the database. </p>
  
  <p>My output should only display the staff name that is not available in the other database. However, this is my output.</p>
  
  <p>Based on the output it only compares the first row. So how do I change my code so that it compares the whole row. Please help me, thank you!</p>