-1

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

    <?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 入门模板创建此站点,我的问题是当显示超过 1 个对象时,它会与前一个对象重叠并搞砸整个布局!

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

遵循 Wesley Murch 的建议后,我现在有另一个问题

现在什么不起作用 http://img21.imageshack.us/img21/4498/screenshotgbf.png

4

1 回答 1

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>a or的唯一有效直接子代<ol><li>

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

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

http://validator.w3.org/

于 2012-12-23T00:43:08.783 回答