title: Comparing Column Values Between Two Tables
body: <p>So I created a little thing here:</p>
  
  <p><a href="http://sqlfiddle.com/#!2/d7a76/1" rel="nofollow">http://sqlfiddle.com/#!2/d7a76/1</a></p>
  
  <p>And it does what I want there, but doesn't work when applied to my actual PHP. On load, the HTML page displays all cable numbers in a dropdown from what is in the 'bundle_lanes' SQL database. But recently my client now wants the cable numbers to disappear if they exist already in the database 'cabletypes'. So I need some way to tell SQL to look for exact cable number match and don't display them if they exist in both tables. What am I doing wrong? It works in the sqlfiddle. No error, just blank results when I run the cableNumbers.php and an empty drop down box.</p>
  
  <p>HTML (index.php)</p>
  
  <pre><code> &lt;body onload="cable_numbers(); company_name();"&gt;
  &lt;select id="cable_no" onchange="update_section_no();" return false;&gt;
                          &lt;option value=""&gt;Cable Number&lt;/option&gt;
                      &lt;/select&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JAVASCRIPT</p>
  
  <pre><code>//Set Cable Numbers in DropDown
  function cable_numbers() {
  $.ajax({
      url: './php/cableNumbers.php',
      dataType: 'json',
      success: function(mydata) {
  
          var combo = document.getElementById("cable_no");
  
              while (combo.firstChild) {
                  combo.removeChild(combo.firstChild);
              };
  
              var option = document.createElement("option");
  
              for (var i = 0; i &lt; mydata.length; i++) {
                  option = document.createElement("option");
                  option.text = mydata[i]['cable_no'];
                  option.value = mydata[i]['cable_no'];
                  try {
                      combo.add(option, null); //Standard
                  } catch (error) {
                      combo.add(option); // IE only
                  }
              };
           section_numbers(); 
      }
  });
  };
  </code></pre>
  
  <p>PHP cableNumbers.php (where the SQL query lives)</p>
  
  <pre><code>$sql = "SELECT DISTINCT cable_no FROM bundle_lanes 
          WHERE (cable_no) NOT IN (SELECT cable_no FROM cabletypes)
          ORDER BY cable_no ASC";
  
  $result = mysql_query($sql) or die ('Error'.mysql_error());
  
  // If DB query successful then send data to calling routine.
  if (mysql_num_rows($result) &gt;= 1)
  {
      while ($row = mysql_fetch_array($result)) {
          $array[] = $row;
      }           
      print json_encode($array);
  }
  </code></pre>