gpt4 book ai didi

PHP Mysql 搜索页面

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

我有一个简单的搜索页面设置,效果很好,但是当我向 mysql 数据库添加一列时,它没有返回任何结果。取出色谱柱,它又可以工作了。我只是不明白我做错了什么。

这是我的searchresults.php如果有帮助的话,我还可以截取数据库布局的屏幕截图。我已经为此苦苦挣扎了几个星期,我需要总结一下

if(!$conn)
{
die("Connection error: " . mysqli_connect_error());
}
$searchterm = $_POST['searchterm'];
$qry = "select * from addresslighting WHERE name LIKE '%".$searchterm."%' UNION
select * from addresslighting WHERE catagory LIKE '%".$searchterm."%' UNION
select * from arealighting WHERE name LIKE '%".$searchterm."%' UNION
select * from arealighting WHERE catagory LIKE '%".$searchterm."%' UNION
select * from bollards WHERE name LIKE '%".$searchterm."%' UNION
select * from bollards WHERE catagory LIKE '%".$searchterm."%' UNION
select * from canopyandgarage WHERE name LIKE '%".$searchterm."%' UNION
select * from canopyandgarage WHERE catagory LIKE '%".$searchterm."%' UNION
select * from canopyandgaragelinears WHERE name LIKE '%".$searchterm."%' UNION
select * from canopyandgaragelinears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from ceilingflush WHERE name LIKE '%".$searchterm."%' UNION
select * from ceilingflush WHERE catagory LIKE '%".$searchterm."%' UNION
select * from commercialceiling WHERE name LIKE '%".$searchterm."%' UNION
select * from commercialceiling WHERE catagory LIKE '%".$searchterm."%' UNION
select * from commercialwall WHERE name LIKE '%".$searchterm."%' UNION
select * from commercialwall WHERE catagory LIKE '%".$searchterm."%' UNION
select * from customcreations WHERE name LIKE '%".$searchterm."%' UNION
select * from customcreations WHERE catagory LIKE '%".$searchterm."%' UNION
select * from directindirectlinears WHERE name LIKE '%".$searchterm."%' UNION
select * from directindirectlinears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from floodlighting WHERE name LIKE '%".$searchterm."%' UNION
select * from floodlighting WHERE catagory LIKE '%".$searchterm."%' UNION
select * from linears WHERE name LIKE '%".$searchterm."%' UNION
select * from linears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from pendantsandchandeliers WHERE name LIKE '%".$searchterm."%' UNION
select * from pendantsandchandeliers WHERE catagory LIKE '%".$searchterm."%' UNION
select * from polelight WHERE name LIKE '%".$searchterm."%' UNION
select * from polelight WHERE catagory LIKE '%".$searchterm."%' UNION
select * from poles WHERE name LIKE '%".$searchterm."%' UNION
select * from poles WHERE catagory LIKE '%".$searchterm."%' UNION
select * from hilowbaylinears WHERE name LIKE '%".$searchterm."%' UNION
select * from hilowbaylinears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from posttopfixtures WHERE name LIKE '%".$searchterm."%' UNION
select * from posttopfixtures WHERE catagory LIKE '%".$searchterm."%' UNION
select * from retrofits WHERE name LIKE '%".$searchterm."%' UNION
select * from retrofits WHERE catagory LIKE '%".$searchterm."%' UNION
select * from undercabinetlinears WHERE name LIKE '%".$searchterm."%' UNION
select * from undercabinetlinears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from vandalresistantlinears WHERE name LIKE '%".$searchterm."%' UNION
select * from vandalresistantlinears WHERE catagory LIKE '%".$searchterm."%' UNION
select * from vanity WHERE name LIKE '%".$searchterm."%' UNION
select * from vanity WHERE catagory LIKE '%".$searchterm."%' UNION
select * from wallpacks WHERE name LIKE '%".$searchterm."%' UNION
select * from wallpacks WHERE catagory LIKE '%".$searchterm."%' UNION
select * from wallsconce WHERE name LIKE '%".$searchterm."%' UNION
select * from wallsconce WHERE catagory LIKE '%".$searchterm."%'";
$rs = mysqli_query($conn,$qry);
$index = 0;
$position = "first";

// This while loop gets all the results and places each one in the $getRowAssoc variable (makes parsing easier)
while ($getRowAssoc = mysqli_fetch_assoc($rs)) {

if($index == 0) {
echo '<div id="container">';
$position = "";
}
elseif($index == 1) {
$position = "";
}
elseif($index == 2) {
$position = "";
}
elseif($index == 3) {
$position = "";
}


echo '<li class="one_quarter'.$position.'">';
echo '<article class="clear">';
echo '<figure class="post-image">';
echo '<a href="'.$getRowAssoc['pdf'].'">';
echo '<img src="'.$getRowAssoc['pic'].'" alt="" style="border:1px solid orange"" height="585" width="585"></img></a>';
echo '<header>';
echo '<h2 class="auto-style3"><a href="'.$getRowAssoc['pdf'].'">'.$getRowAssoc['name'].'</a></h2>';
echo '<div class="blog-post-meta">';
echo '<ul>';
echo '<li class="blog-post-cats">Catagories:<a href="'.$getRowAssoc['catagorylink'].'">'.$getRowAssoc['catagory'].'</a>';
echo '</li>';
echo '</ul>';
echo '</div>';
echo '</header>';
echo '<p>'.$getRowAssoc['description'].'</p>';
echo '<p>*See Specification Sheet for Details.</p>';
echo '<footer class="read-more"><a href="'.$getRowAssoc['pdf'].'">Download Specification Sheet &raquo;</a>';
echo '</footer>';
echo '</article>';
echo '</li>';

$index++;
if($index == 4) {
echo '</div>';
$index = 0;
}
}
?>

最佳答案

只有当您的表具有相同数量/名称的列时,UNION 才会起作用。除非您将 SELECT 指定为所有没有该列的表的 SELECT null 值。那么,我假设所有这些 table 都有完全相同的布局?如果是这样,则您添加到其中的任何列都需要添加到所有列。

此外,这里还有很多工会。有没有想过使用 OR?

select * from canopyandgaragelinears WHERE name LIKE '%".$searchterm."%' OR catagory LIKE '%".$searchterm."%'

关于PHP Mysql 搜索页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51406497/

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