title: Setting specific table cell value into textbox (jQuery / PHP)
body: <p>I have 1 table with 2 columns. We'll call it col Number and col Letter. It appears as such:</p>
  
  <pre><code>1  |  A
  2  |  B
  3  |  C
  4  |  D
  </code></pre>
  
  <p>I have 1 select2 drop down box that has a loop of all the Numbers - and a text box I would like to have the Letter appear that correlates with that number.</p>
  
  <p>HTML/PHP querying current table</p>
  
  <pre><code>&lt;label for="number"&gt;NUMBER&lt;/label&gt;
  &lt;select onChange="setLetter(this)" style="text-transform: uppercase;" class="form-control select2" style="width: 100%;" name="number" id="number"&gt;
      &lt;option selected="selected" disabled="disabled"&gt;-Select-&lt;/option&gt;
  
      &lt;?php
      if ($result-&gt;num_rows &gt; 0) {
          // output data of each row
          while($row = $result-&gt;fetch_assoc()) {
              echo "&lt;option name='".$row["Number"]."' value='".$row["Number"]."'&gt;";
              echo $row["number"];
              echo "&lt;/option&gt;";
          }
      } else {
          echo "0 results";
      }
      $conn-&gt;close();
      ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JavaScript attempt at querying the value of the select2 box</p>
  
  <pre><code>function setLetter(sel)
  {
      var col = sel.value;
      &lt;?php
      $number = "SELECT ['Letter'] FROM `msftrail` WHERE ['Number']= '".$col."'";
      ?&gt;
      var php_var = "&lt;?php echo $number; ?&gt;";
      $("#letter").val(php_var);
  }
  </code></pre>
  
  <p>How can I populate the Letter text box with the cell in the table that correlates with the correct number?</p>