列表中的重叠项目

时间:2012-12-23 00:39:02

标签: php html

最近我在尝试创建搜索表单并在列表中显示结果时遇到了问题

    <?php 
        require_once ("Includes/simplecms-config.php"); 
        require_once  ("Includes/connectDB.php");
        include("Includes/header.php");         
     ?>

    <div id="main">
        <div id="searchcontent">
            <?php 
                $querysuccess = FALSE;
                $extsuccess = FALSE;
                if($_GET["query"] != "")
                {
                    echo '<h3>Results for "'.$_GET["query"].'"</h3>';
                    $querysuccess = TRUE;
                }

                if($_GET["ext"] != "*" && $_GET["ext"] != "")
                {
                    echo "<p>Matching extension: *.".$_GET["ext"]."</p>";
                    $extsuccess = TRUE;
                }
                else if($_GET["ext"] == "")
                {
                    echo "<p>No extension specified</p>";
                }
                else
                {
                    $extsuccess = TRUE;
                }

                if($querysuccess == TRUE && $extsuccess == TRUE)
                {
                    doSearch();
                }

                function doSearch()
                {
                    $query = $_GET["query"];
                    $extension = $_GET["ext"];

                    $sql_query = "SELECT * FROM search WHERE";
                    $querycount = 0;

                    $terms = explode(" ", $query);

                    foreach($terms as $word)
                    {
                        $querycount++;
                        if($querycount == 1) {
                            $sql_query .= " description LIKE '%$word%'";
                        }
                        else
                        {
                            $sql_query .= " OR description LIKE '%$word%'";
                        }
                    }

                    if($searchforextension == TRUE)
                    {
                        $sql_query .= "AND extension='$extension'";
                    }

                    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
                    mysql_select_db(DB_NAME);

                    $sql_query = mysql_query($sql_query);
                    $numrows = mysql_num_rows($sql_query);
                    if($numrows > 0)
                    {
                        echo "<ul>";
                        while($proc_row = mysql_fetch_array($sql_query))
                        {
                            $script_id = $proc_row["id"];
                            $script_name = $proc_row["name"];
                            $script_description = $proc_row["description"];
                            $script_author = $proc_row["author"];
                            $script_authorURL = $proc_row["authorURL"];
                            $script_pathname = $proc_row["filename"];

                            $search_result = "<li><div class='result'>";
                            $search_result .= " <p class='result_title'>$script_name</p>";
                            $search_result .= " <p>$script_description</p>";
                            $search_result .= " <div class='result_footer'>";
                            $search_result .= "     <a href='$script_authorURL'"." class='result_author'>$script_author</a>";
                            $search_result .= "     <a href='/getscript.php?script=$script_id" . "&". "file=$script_pathname' class='result_download'>View</a>";
                            $search_result .= " </div>";
                            $search_result .= "</div></li><br /><br /><br />";
                            echo $search_result;

                        }
                        echo "</ul>";
                    }
                    else
                    {
                        echo "<br/><h2>Unable to find any results matching your query.</h2>";
                    }

                    mysql_close();
                }
            ?>
        </div>
    </div>

    </div>

    <?php 
        include ("Includes/footer.php");
     ?>

我正在使用Microsoft WebMatrix 2.0基于PHP启动器模板创建此站点,我的问题是当显示多个对象时它会覆盖前一个对象并搞砸整个布局!

如果需要,我可以发布部分CSS吗?

按照Wesley Murch的建议,我现在有另一个问题

What's not working now http://img21.imageshack.us/img21/4498/screenshotgbf.png

1 个答案:

答案 0 :(得分:3)

您正在生成无效的HTML。

在此处,您关闭了<a>标记</p>,该标记不正确:

$search_result .= "     <a href='/getscript.php?script=$script_id" . "&". "file=$script_pathname' class='result_download'>View</p>";

在此处您添加<br>代码作为<ul>的直接子代,该代码无效:

$search_result .= "</div></li><br /><br /><br />";

<ul><ol>唯一有效的直接子女为<li>

您还可以在HTML顶部打开2个div,但是底部有3个结束标记。

无效的HTML是布局中断的主要原因之一。将来使用此工具作为调试HTML和/或CSS的第一站:

http://validator.w3.org/