簡體   English   中英

如何修復我的 php 論壇的 href 論壇鏈接標簽?

[英]How do I fix the href forum link tags for my php forum?

現在我正在開發一個創建論壇的 php 項目。 論壇有3個類別,每個類別有3個子類別。 現在我正在嘗試獲取 href 鏈接以將我發送到正確的頁面: http://localhost/RoyalReader/RoyalReaderForum/topics.php?cid=1&scid=1在那里我可以創建新帖子,回復到現有帖子,並刪除/退出到其他帖子,但是 index.php 上的鏈接不斷將我發送到: http://localhost/RoyalReader/RoyalReaderForum/topics/1/1 ,在那里我收到“內容不存在”錯誤。 我想知道如何修復此錯誤並傳送到正確的鏈接。

cid=categority id 又名論壇的類別和 scid=sub-category id,我需要能夠轉到不同的類別和子類別 id。 這是我的 index.php

    include ('layout_manager.php');
    include ('content_function.php');
?>
<html>
    <head><title>Royal Reader's forum</title></head>
    <link href="/RoyalReader/RoyalReaderForum/forum.css" type="text/css" rel="stylesheet" />
    <body>
        <div class="pane">
            <div class="header"><h1><a href="/RoyalReaderForum">Royal Reader Forum</a></h1></div>
            <div class="loginpane">
                <?php
                    session_start();
                    if(isset($_SESSION['username'])) {
                        //logout function
                        logout();
                    } else {
                        if (isset($_GET['status'])) {
                            if ($_GET['status'] == 'reg_success') {
                                echo "<h1 style='color: green;'>new user registered successfully!</h1>";
                            } else if ($_GET['status'] == 'login_fail') {
                                echo "<h1 style='color: red;'>invalid username and/or password!</h1>";
                            }
                        }
                        loginform();
                    }
                ?>
            </div>
            <div class="forumdesc">
                <p>Welcome to the Royal Reader Forum, the best place for connecting to readers and authors just like you!</p>
            </div>
            <div class="content">
                <?php dispcategories(); ?>
            </div>
        </div>
    </body>
</html>

這是我在 content_function.php 中操作 hrefs 的地方

    function dispcategories() {
        include ('dbconn.php');

        $select = mysqli_query($con, "SELECT * FROM categories");

        while ($row = mysqli_fetch_assoc($select)) {
            echo "<table class='category-table'>";
            echo "<tr><td class='main-category' colspan='2'>".$row['category_title']."</td></tr>";
            dispsubcategories($row['cat_id']);
            echo "</table>";
        }
    }

    function dispsubcategories($parent_id) {
        include ('dbconn.php');
        $select = mysqli_query($con, "SELECT cat_id, subcat_id, subcategory_title, subcategory_desc FROM categories, subcategories 
                                      WHERE ($parent_id = categories.cat_id) AND ($parent_id = subcategories.parent_id)");
        echo "<tr><th width='90%'>Categories</th><th width='10%'>Topics</th></tr>";
        while ($row = mysqli_fetch_assoc($select)) {
            echo "<tr><td class='category_title'><a href='/RoyalReader/RoyalReaderForum/topics/".$row['cat_id']."/".$row['subcat_id']."'>
                  ".$row['subcategory_title']."<br />";
            echo $row['subcategory_desc']."</a></td>";
            echo "<td class='num-topics'>".getnumtopics($parent_id, $row['subcat_id'])."</td></tr>";
        }
    }

    function getnumtopics($cat_id, $subcat_id) {
        include ('dbconn.php');
        $select = mysqli_query($con, "SELECT category_id, subcategory_id FROM topics WHERE ".$cat_id." = category_id 
                                      AND ".$subcat_id." = subcategory_id");
        return mysqli_num_rows($select);
    }

    function disptopics($cid, $scid) {
        include ('dbconn.php');
        $select = mysqli_query($con, "SELECT topic_id, author, title, date_posted, views, replies FROM categories, subcategories, topics 
                                      WHERE ($cid = topics.category_id) AND ($scid = topics.subcategory_id) AND ($cid = categories.cat_id)
                                      AND ($scid = subcategories.subcat_id) ORDER BY topic_id DESC");
        if (mysqli_num_rows($select) != 0) {
            echo "<table class='topic-table'>";
            echo "<tr><th>Title</th><th>Posted By</th><th>Date Posted</th><th>Views</th><th>Replies</th></tr>";
            while ($row = mysqli_fetch_assoc($select)) {
                echo "<tr><td><a href=http://localhost/RoyalReader/RoyalReaderForum/topics.php?cid=1&scid=1>{$row['title']}</a></td><td>{$row['author']}</td><td>{$row['date_posted']}</td><td>{$row['views']}</td><td>{$row['replies']}</td></tr>";
            }
            echo "</table>";
        } else {
            echo "<p>this category has no topics yet!  <p>this category has no topics yet!<a href=http://localhost/RoyalReader/RoyalReaderForum/topics.php?cid=1&scid=1>>
                 add the very first topic to RoyalReader now</a></p>";
        }
    }
?>```

thank you to anyone in advance who can help. 

你把這些 URL 放在這里,所以你可以將它們更改為默認filename.php?var1=1&var2=1

<a href='/RoyalReader/RoyalReaderForum/topics/".$row['cat_id']."/".$row['subcat_id']."'>

要將 /1/1 用作 PHP 變量,您可以使用.htaccess文件和 QSA 標志重定向這些值。

RewriteRule ^parts/([^/\.]+)/([^/\.]+)/?$ parts.php?p=$1&f=$2 [L,QSA]

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM