gpt4 book ai didi

php - sql搜索结果太多也有错

转载 作者:行者123 更新时间:2023-11-30 21:55:41 26 4
gpt4 key购买 nike

代码:

<?php
include("config.php");
mysql_connect("Localhost" , "root" , "") or die(mysql_error());
mysql_select_db("imprimante");
if(isset($_POST["submit"])){
$search = $_POST["search"];
$sql = mysql_query("SELECT * FROM `inventar` i , `evidenta` e WHERE
(i.`ID_M` = '".$search."' and i.`ID_M` = e.`ID_M`) OR (i.`model` LIKE
'".$search."') OR (e.`data_intrare` = '".$search."') OR (e.`data_iesire` =
'".$search."') OR (i.`user` LIKE '".$search."' and i.`user` =
e.`user_iesire`) OR (i.`dept` LIKE '".$search."' and i.`dept` = e.`dept`) OR
(i.`tip` LIKE '".$search."') OR (i.`COD` like '".$search."') OR (i.`SERIA`
LIKE '".$search."') OR (i.`NR_INV` LIKE '".$search."')");

if(!$search){
echo "Nu ai cautat nimic...";
} else {

//WHILE PT RESULTURI
while($row = mysql_fetch_array($sql)){
echo '<br/> Model: '.$row['model'];
echo '<br/> ID Model: '.$row['ID_M'];
echo '<br/> Data Intrare: '.$row['data_intrare'];
echo '<br/> Data Iesire: '.$row['data_iesire'];
echo '<br/> User: '.$row['user'];
echo '<br/> User Iesire: '.$row['user_iesire'];
echo '<br/> Departament: '.$row['dept'];
echo '<br/> Tip Consumabil: '.$row['tip'];
echo '<br/> Cod Produs: '.$row['cod'];
echo '<br/> Seria: '.$row['SERIA'];
echo '<br/> Numar Inventar: '.$row['NR_INV'];
echo '<br/><br/>';
}
}
}?>
<html>
<head><title>Search Function</title></head>
<body>
<form action="search.php" method=POST>
<input type=text name="search" placeholder="Cauta"><br/><br/>
<input type=submit value="Cauta" name="submit"><br/><br/>
<button name="Index"><a href="../index.php">Index</a></button>
<button name="Evidenta"><a href="evidenta.php">Evidenta</a></button><br/>
</form>
</body>
</html>

为什么这个查询返回的结果总是比我在我的数据库中实际拥有的结果多,而且还返回错误的结果?

顺便说一句,“inventar”和“evidenta”这两个表通过 ID_M 建立了关系

谢谢你的帮助:D

最佳答案

请测试此查询(我认为您必须在查询中管理'OR'):

<?php

mysql_query("SELECT *
FROM `inventar` i , `evidenta` e
WHERE ( i.`ID_M` = '" . $search . "'
AND i.`ID_M` = e.`ID_M`
)
OR ( (i.`model` LIKE '" . $search . "')
OR (e.`data_intrare` = '" . $search . "')
OR (e.`data_iesire` = '" . $search . "')
OR ( i.`user` LIKE '" . $search . "'
AND i.`user` = e.`user_iesire`
)
OR ( i.`dept` LIKE '" . $search . "'
AND i.`dept` = e.`dept`
)
OR (i.`tip` LIKE '" . $search . "')
OR (i.`COD` like '" . $search . "')
OR (i.`SERIA` LIKE '" . $search . "')
OR (i.`NR_INV` LIKE '" . $search . "')
)"
);

关于php - sql搜索结果太多也有错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45275587/

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