title: html form select option, assign SQL query to each option on select
body: <p>I have a select option form that is self referencing, How do I assign the SQL query to each select option? so when the user selects, that selection queries the database for that specific table and outputs to page. I have a select option for each table in the database and have created the related queries. Do I need to put the queries into an array? I am stuck on how to advance further. I have included some of the code below. Do I need to create a unique SQL query var for each user option? Any direction would be helpful. Thanks</p>
  
  <pre><code>    //this is the first query it gets the count for pagination
          $sql = "SELECT COUNT(productCode) FROM products"
          or die ('Cannot Select database');  
  
  
      // This  query is just to get the total count of rows
      //$sql = "SELECT COUNT(productCode) FROM products";
      $query = $dbc-&gt;query($sql);
  
  $row = $query-&gt;fetch_row();
  //this is were I am stuck
      if($_POST['productCode'] == ('productCode')) {
      // query to get code records
      $sql2 = "SELECT productCode FROM products";
  }
  elseif($_POST['productName'] == 'productName') {
      // query to get product name  records
      $sql3 = "SELECT productName FROM products";
  } else {
      // query to get all records
      $sql4 = "SELECT * FROM products";
  }
      $list = '';
  
      while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
          $id = $row['productCode'];
          $name = $row['productName'];
          $line = $row['productLine'];
          $scale = $row['productScale'];
          $vendor = $row['productVendor'];
          $description = $row['productDescription'];
          $buy_price = $row['buyPrice'];
          $quanity = $row['quantityInStock'];
          $msrp = $row['MSRP'];
          $list .= "&lt;table&gt;
          &lt;tr&gt; 
              &lt;td class='center'&gt;&lt;strong&gt;Product Id&lt;/strong&gt;&lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class='center'&gt;$id&lt;/td&gt; 
              &lt;td&gt;$name&lt;/td&gt;
              &lt;td&gt;$product_line&lt;/td&gt;
              &lt;td&gt;$scale&lt;/td&gt;
              &lt;td&gt;$vendor&lt;/td&gt;
              &lt;td&gt;$description&lt;/td&gt;
              &lt;td&gt;$buy_price&lt;/td&gt;
              &lt;td&gt;$quanity&lt;/td&gt;
              &lt;td&gt;$msrp&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt;";
      }
      &lt;select name="value"&gt;
              &lt;option value="&lt;?=$id; ?&gt;"&gt;Product ID&lt;/option&gt;
              &lt;option value="&lt;?=$name; ?&gt;"&gt;Product Name&lt;/option&gt;
              &lt;option value="&lt;?=$line; ?&gt;"&gt;Product Line&lt;/option&gt;
              &lt;option value="&lt;?=$scale; ?&gt;"&gt;Product Scale&lt;/option&gt;
              &lt;option value="&lt;?=$vendor; ?&gt;"&gt;Product Vendor&lt;/option&gt;
              &lt;option value="&lt;?=$description; ?&gt;"&gt;Product Description&lt;/option&gt;
              &lt;option value="&lt;?=$quanity; ?&gt;"&gt;Quanity In Stock&lt;/option&gt;
              &lt;option value="&lt;?=$buy_price; ?&gt;"&gt;Buy Price&lt;/option&gt;
              &lt;option value="&lt;?=$msrp; ?&gt;"&gt;MSRP&lt;/option&gt;
       &lt;/select&gt;
  </code></pre>