让我从这开始......我从来没有使用过.php脚本编程,而且编程方面还比较新,我正在开发一个以Android Studio IDE为中心的新项目,我通常用JAVA编写。我一直在尝试使用下面的.php脚本,我已根据需要进行修改。它工作得很好但是,我无法弄清楚如何进行多查询,基本上我希望得到我的回声'但是如果有一个匹配到FSC / NIIN字段,那么它应该显示额外的匹配。
返回历史记录,为某些FSC / NIIN字段列出了多个部件号,我正在努力让它显示与库存号(FSC / NIIN)匹配的其他部件号。非常感谢任何帮助或建议!
<?php
require "conn.php";
$FSC = $_POST["FSC"];
$NIIN = $_POST["NIIN"];
$mysql_qry = "select * from MYTAB where FSC like '$FSC' and NIIN like
'$NIIN';";
$result = mysqli_query($conn ,$mysql_qry);
if(mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$PART_NUMBER = $row["PART_NUMBER"];
$FSC = $row["FSC"];
$NIIN = $row["NIIN"];
$ITEM_NAME = $row["ITEM_NAME"];
echo $ITEM_NAME, ", " .$PART_NUMBER, ", " .$FSC, ", " .$NIIN;
} else {
echo "Query Failed! - No such NSN is loaded to the database! Please double
check the information is correct and resubmit request...";
}
mysqli_close($con);
?>
答案 0 :(得分:1)
您需要循环结果:
....
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) { //<-----
$PART_NUMBER = $row["PART_NUMBER"];
$FSC = $row["FSC"];
$NIIN = $row["NIIN"];
$ITEM_NAME = $row["ITEM_NAME"];
echo $ITEM_NAME, ", " .$PART_NUMBER, ", " .$FSC, ", " .$NIIN;
}
} else {
...
你应该使用预备语句,看看如何在这里: How can I prevent SQL injection in PHP?