gpt4 book ai didi

JavaScript - 如何从下拉选择中执行特定查询?

转载 作者:行者123 更新时间:2023-11-29 18:29:19 26 4
gpt4 key购买 nike

我想通过根据用户选择执行某些特定查询来简化我的代码

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

  //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 个下拉菜单,用户只能根据他们在下拉列表中选择的内容看到。我还不明白的是在我的代码上这样做。感谢任何人的帮助。

附: :根据查询显示的内容,假设从数据库中查看数据

最佳答案

php:

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

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

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

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

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

$query = $select[$_GET["query_select"]]." ".
$where[$_GET["query_where"]]." ".$and1[$_GET["query_and1"]].
" ".$and1[$_GET["query_and2"]]." ".$group[$_GET["query_group"]];

html:

<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>

我希望你明白一个想法

关于JavaScript - 如何从下拉选择中执行特定查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45852778/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com