gpt4 book ai didi

php - 为什么我的代码甚至列出了这些?

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

我正在尝试编写一个搜索功能,它列出符合搜索条件的产品。

termekek = products
marka = manufacturer
tipus = type

正如您在下图中看到的,它列出了我的产品,这些产品是 MSI 但也不是 Radeon。它应该只列出产品,即 MSi,也包括 Radeon。在我看来,问题一定出在我的 SQL 代码上,但我似乎无法把它弄对。先感谢您! My problem

我的 PHP 代码:

http://pastebin.com/fmwLVbER

           <?php

if(isset($_GET["text_search"]))
{
require('db.php');
mysql_select_db('ceg',$connection);
$text=$_GET["text_search"];

$text=explode(" ", $text);

$i=1;

if(count($text) > 0)
$sql='SELECT * FROM termekek WHERE marka="'.$text[0].'" OR tipus="'.$text[0].'" ';

while($i < count($text)){
$sql .= 'AND marka="'.$text[$i].'" OR tipus="'.$text[$i].'"';
$i++;
}

echo $sql;

$result=mysql_query($sql);

if (mysql_num_rows($result) > 0)
{
while($array=mysql_fetch_array($result)){
echo '<div id="product">
<div>
<img height="250" width="250" src='.$array["kep"].' />
</div>
<div>
'.$array["marka"].'
'.$array["tipus"].'
</div>
<div>
'.$array["ar"].' euró
</div>
</div>';
}
}
}

?>

最佳答案

您的 OR 子句需要用括号括起来,以便首先对它们进行求值。

关于php - 为什么我的代码甚至列出了这些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20809555/

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