php mysql搜索页面

ruoxqz4g  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(325)

我有一个简单的搜索页面设置,工作得很好,但是当我添加一列到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;
    }
}
?>
b91juud3

b91juud31#

只有当表的列数/列名相同时,联合才会起作用。除非指定要选择的“选择” null 所有没有列的表的值。所以,我假设所有这些表都有完全相同的布局?如果是这样的话,任何一列您添加到一个,您将需要添加到所有。
此外,这里还有很多工会。有没有想过用或?

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

相关问题