gpt4 book ai didi

php - 显示包含搜索条件的搜索结果

转载 作者:太空宇宙 更新时间:2023-11-03 12:24:30 25 4
gpt4 key购买 nike

我已经为我的页面编写了搜索代码,但是我希望它显示包含搜索条件的产品...目前它只显示以 cirteria 开头的结果。

这是我的代码:

<?php
$name = $_GET["q"];
if ($name <= "") {
echo ("");
}
else {
$con = mysql_connect("localhost", "cl49-XXX", "vogalcms");
if (!$con) {
die('Could not connect: line 513 ' . mysql_error());
}
mysql_select_db("cl49-XXX", $con) or die("Unable to select database");
$result = mysql_query("SELECT * FROM products WHERE `prodname` LIKE '$name%' ") or die('Error: Line 519 (' . mysql_error() . ')');
mysql_select_db("cl49-vogalcms", $con) or die("Unable to select database");


while ($row = mysql_fetch_array($result)) {
$prodID = $row['prodID'];
$prodname = $row['prodname'];
$catagory = $row['catagory'];
echo "
<div class='row-fluid portfolio-block'>
<div class='span5 portfolio-text'>
<img src='admin/userpics/$prodID.jpg' height='50' width='50' alt='' />
<div class='portfolio-text-info'>
<h4>$prodname</h4>
<p></p>
</div>
</div>
<div class='span5'>
<div class='portfolio-info'>
Product ID
<span>$prodID</span>
</div>
<div class='portfolio-info'>
catagory
<span>$catagory</span>
</div>
</div>
<div class='span2 portfolio-btn'>
<a href='edit_product.php?q=$prodID' class='btn bigicn-only'><span>View/Edit</span></a>
</div>
</div> ";
}
}
?>

我希望能够搜索 ca 而不仅仅是显示 CAr、CArpet,还显示 nesCAfe?

最佳答案

只需将您的 where 子句更改为:

WHERE `prodname` LIKE '%$name%' 

关于php - 显示包含搜索条件的搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18250254/

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