$ _GET [' id']无法获取ID

时间:2016-11-15 22:28:21

标签: php

            <?php
            //categoryview.php
            include 'connection.php';
            include 'header.php';
             mysql_select_db('forum');
            //first select the category based on $_GET['cat_id'
            $id= mysql_real_escape_string($_GET['id']);
            $sql = "SELECT
                        forum_id,
                        forum_name,
                        forum_description
                    FROM
                        forums
                    WHERE
                        forum_id = '".$id."'";
            $result = mysql_query($sql);

            if(!$result)
            {
                echo 'The category could not be displayed, please try again later.' . mysql_error();
            }
            else
            {
                if(mysql_num_rows($result) == 0)
                {
                    echo 'This category does not exist.';
                    mysql_error();
                }   
                else
                {
                    //display category data
                    while($row = mysql_fetch_assoc($result))
                    {
                        echo '<h2>Topics in ′' . $row['forum_name'] . '′ category</h2>';
                    }

            //do a query for the topics
            $sql = "SELECT  
                        thread_id,
                        thread_subject,
                        thread_date,
                        thread_category
                    FROM
                        threads
                    WHERE
                        threads.thread_category = '".$id."'";

            $result = mysql_query($sql);

            if(!$result)
            {
                echo 'The topics could not be displayed, please try again later.';
                echo mysql_error();
            }
            else
            {
                if(mysql_num_rows($result) == 0)
                {
                    echo 'There are no topics in this category yet.';
                }
                else
                {
                    //prepare the table
                    echo '<table border="1">
                          <tr>
                            <th>Topic</th>
                            <th>Created at</th>
                          </tr>'; 

                    while($row = mysql_fetch_assoc($result))
                    {               
                        echo '<tr>';
                            echo '<td class="leftpart">';
                                echo '<h3><a href="topic.php?id=' . $row['thread_id'] . '">' . $row['thread_subject'] . '</a><h3>';
                            echo '</td>';
                            echo '<td class="rightpart">';
                                echo date('d-m-Y', strtotime($row['thread_date']));
                            echo '</td>';
                        echo '</tr>';
                    }
                }
            }
        }
    }


    ?>

嘿伙计我的$_GET['id']有问题。当我尝试加载此页面时,它应该显示在我点击的论坛中创建的线程。数据库中的forum_id包含整数值。例如论坛命名园艺有整数1。 我面临的问题是,当我从索引页面点击论坛时,此页面加载,网址栏显示http://localhost/forum/categoryview.php?id,当我在结尾处添加php?id=1时,园艺论坛中的所有主题都会显示达

index.php

            <?php
            include 'connection.php';
            include 'header.php';
             mysql_select_db('forum');
            $sql = "SELECT
                        forum_id,
                        forum_name,
                        forum_description
                    FROM
                        forums";

            $result = mysql_query($sql);

            if(!$result)
            {
                echo 'The categories could not be displayed, please try again later.';
                echo mysql_error();
            }
            else
            {
                if(mysql_num_rows($result) == 0)
                {
                    echo 'No categories defined yet.';
                    echo mysql_error();
                }   
                else
                {
                    //prepare the table
                    echo '<table border="1">
                          <tr>
                            <th>Category</th>
                            <th>Last topic</th>
                          </tr>'; 

                    while($row = mysql_fetch_assoc($result))
                    {               
                        echo '<tr>';
                            echo '<td class="leftpart">';
                                echo '<h3><a href="categoryview.php?id">' . $row['forum_name'] . '</a></h3>' . $row['forum_description'];
                            echo '</td>';
                            echo '<td class="rightpart">';
                                        echo '<a href="topic.php?id=">Topic subject</a> at 10-10';
                            echo '</td>';
                        echo '</tr>';
                    }

                }
            }

            ?>

那是链接到categoryview的索引页面。当你点击forum_name时,它会带你到categoryview,它显示该论坛中的所有主题

0 个答案:

没有答案