搜索表单会打破整个页面

时间:2014-04-11 12:22:17

标签: php css

我为我的网站找到了一个搜索表单教程。代码正在运行,但是当搜索查询有结果时,它会破坏整个页面。我的意思是网站的css负载减半。但如果没有搜索结果,网站就可以了。 以下是网站和脚本的外观。

<!DOCTYPE html>
<html>
<head>
<title>Searching...</title>
<link rel="icon"  type="image/x-icon"  href="media/favicon.ico" />
<link rel="stylesheet" type="text/css" href="include/style.css">

</head>
<body>
<div id="wrapper">
<div id="container">
    <?php include 'include/header.php'; ?>
    <div id="main">
        <div id="column_left">
            <?php
            $button = $_GET ['submit'];
            $search = $_GET ['search'];
            if(strlen($search)<=4)
                echo "Please enter at least 4 symbols to search";
            else{
                echo "Search terms: <b>$search</b> <hr size='1'></br>";
                mysql_connect("localhost","root","");
                mysql_select_db("image");
                $search_exploded = explode (" ", $search);
                foreach($search_exploded as $search_each)
                {
                    $x++;
                    if($x==1)
                        $construct .="caption LIKE '%$search_each%'";
                    else
                        $construct .="caption LIKE '%$search_each%'";
                }
                $constructs ="SELECT *, caption, alt FROM images WHERE $construct";
                $run = mysql_query($constructs);
                $foundnum = mysql_num_rows($run);
                if ($foundnum==0)
                    echo "There is no results for:  <b>$search</b>.";
                else
                {
                    echo "Found: $foundnum results !<p>";
                    $per_page = 1;
                    $start = $_GET['start'];
                    $max_pages = ceil($foundnum / $per_page);
                    if(!$start)
                        $start=0;
                    $getquery = mysql_query("SELECT caption, name, alt FROM images WHERE $construct LIMIT $start, $per_page");
                    while($runrows = mysql_fetch_assoc($getquery))
                    {
                        echo "<img style=\"width:100%;margin:0 auto;\" src=\"/upload/".$runrows['name']."\" /><br />";
                        echo "<h1>" . $runrows['caption'] . "</h1>";
                    }
                    $prev = $start - $per_page;
                    $next = $start + $per_page;
                    $adjacents = 3;
                    $last = $max_pages - 1;
                    if($max_pages > 1)
                    {
                        if (!($start<=0))
                            echo " <a href='search.php?search=$search&start=$prev'>Предишна</a> ";

                        if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
                        {
                            $i = 0;
                            for ($counter = 1; $counter <= $max_pages; $counter++)
                            {
                                if ($i == $start){
                                    echo" <a href='search.php?search=$search&start=$i'><b>$counter</b></a> ";
                                }
                                else {
                                    echo " <a href='search.php?search=$search&start=$i'>$counter</a> ";
                                }
                                $i = $i + $per_page;
                            }
                        }
                        elseif($max_pages > 5 + ($adjacents * 2))
                        {
 //close to beginning; only hide later pages
                            if(($start/$per_page) < 1 + ($adjacents * 2))
                            {
                                $i = 0;
                                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                                {
                                    if ($i == $start){
                                        echo " <a href='search.php?search=$search&start=$i'><b>$counter</b></a> ";
                                    }
                                    else {
                                        echo " <a href='search.php?search=$search&start=$i'>$counter</a> ";
                                    }
                                    $i = $i + $per_page;
                                }
                            }
 //in middle; hide some front and some back
                            elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
                            {
                                echo " <a href='search.php?search=$search&start=0'>1</a> ";
                                echo " <a href='search.php?search=$search&start=$per_page'>2</a> .... ";
                                $i = $start;
                                for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
                                {
                                    if ($i == $start){
                                        echo " <a href='search.php?search=$search&start=$i'><b>$counter</b></a> ";
                                    }
                                    else {
                                        echo " <a href='search.php?search=$search&start=$i'>$counter</a> ";
                                    }
                                    $i = $i + $per_page;
                                }
                            }
   //close to end; only hide early pages
                            else
                            {
                                echo " <a href='search.php?search=$search&start=0'>1</a> ";
                                echo " <a href='search.php?search=$search&start=$per_page'>2</a> .... ";
                                $i = $start;
                                for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
                                {
                                    if ($i == $start){
                                        echo " <a href='search.php?search=$search&start=$i'><b>$counter</b></a> ";
                                    }
                                    else {
                                        echo " <a href='search.php?search=$search&start=$i'>$counter</a> ";
                                    }
                                    $i = $i + $per_page;
                                }
                            }
                        }
 //next button
                        if (!($start >=$foundnum-$per_page))
                            echo " <a href='search.php?search=$search&start=$next'>Следваща</a> ";
                    }
                }
            }
            ?>

            <div id="fb_com"> <script>document.write("<div class='fb-comments' data-href='" + window.location.href + "'data-num-posts='5' data-width='680'></div>");</script></div>
        </div>
        <?php include 'include/right.php'; ?>
        <br/>
        <?php include 'include/footer.php'; ?><br/>
    </div>
</div>
</div>
 </body>
 </html>

知道出了什么问题吗?

0 个答案:

没有答案