JavaScript - 如何从下拉列表中执行某些查询?

时间:2017-08-24 04:06:40

标签: javascript php html mysql ajax

我希望根据用户选择的内容执行某些查询来简化我的代码

这个想法是当用户第一次访问该页面时,用户将通过此查询显示基于Base + group的查询。但接下来,他们可以决定从下面的下拉列表中看到哪些数据

  //Base
  $Material = "SELECT MATERIAL, COUNT(MATERIAL) AS 'TOTAL' FROM `khitable` ";
  $StorageLocation = "SELECT SLOC ,COUNT(SLOC) AS 'TOTAL' FROM `khitable`";
  $VerifStock = "SELECT VERIF_STOCK ,COUNT(VERIF_STOCK) AS 'TOTAL' FROM `khitable`";

  //Tipe Pipa
  $ERW = "WHERE MATERIAL LIKE '%ER%'";
  $SP = "WHERE MATERIAL LIKE '%SP%'";
  $ACC = "WHERE MATERIAL LIKE '%ACC%'";

  //Status Pengerjaan
  $FG = "AND MATERIAL NOT LIKE '%SF-%'";
  $WIP = "AND MATERIAL LIKE '%SF-%'";

  //Ketersediaan
  $SO = "AND SO_NUMBER NOT LIKE '%605%'";
  $Buffer = "AND SO_NUMBER LIKE '%605%'";
  $FS = "AND MATERIAL LIKE '%-FS%";

  //Group By
  $GroupMaterial = "GROUP BY MATERIAL";
  $GroupSLOC = "GROUP BY SLOC";
  $GroupVerifStock = "GROUP BY VERIF_STOCK";

并且下一位用户可以从下面的下拉列表中选择要显示的数据

<div class="row">
  <div class="input-field col s4">      
    <select class="validate">
      <option value="" disabled selected>Pilih pilihan anda</option>
      <option value="1">Finish Good</option>
      <option value="2">Semi Finish (WIP)</option>
    </select>
    <label >Pilih Berdasarkan Status Pengerjaan</label>
  </div>
  <div class="input-field col s4">      
    <select class="validate">
      <option value="" disabled selected>Pilih pilihan anda</option>
      <option value="1">Sales Order</option>
      <option value="2">Buffer</option>
      <option value="3">Free Stock</option>
    </select>
    <label >Pilih Berdasarkan Status Ketersediaan</label>
  </div>
</div>

所以有2个下拉列表,用户只能看到他们在下拉列表中选择的内容。我不明白的是我的代码是这样做的。感谢任何人的帮助。

P.S。 :假设根据显示的查询

从数据库中查看数据

2 个答案:

答案 0 :(得分:0)

PHP:

<form action="yourscript.php" method="get">
<!-- here is your form elements for material,storagelocation etc -->
  .................
<div class="row">
  <div class="input-field col s4">      
    <select class="validate" name="query_and1">
      <option value="" disabled selected>Pilih pilihan anda</option>
      <option value="FG">Finish Good</option>
      <option value="WIP">Semi Finish (WIP)</option>
    </select>
    <label >Pilih Berdasarkan Status Pengerjaan</label>
  </div>
  <div class="input-field col s4">      
    <select class="validate" name="query_and2">
      <option value="" disabled selected>Pilih pilihan anda</option>
      <option value="SO">Sales Order</option>
      <option value="Buffer">Buffer</option>
      <option value="FS">Free Stock</option>
    </select>
    <label >Pilih Berdasarkan Status Ketersediaan</label>
  </div>
</div>
 ............
 </form>

HTML:

start /min /c "" Music.mp3

我希望你理解一个想法

答案 1 :(得分:0)

查看以下示例链接,了解有关如何使用ajax提交数据并获取结果的更多详细信息

https://www.w3schools.com/php/php_ajax_database.asp