根据点击的类别显示不同的HTML页面标题时出现问题 [英] Problem in displaying different HTML page headers according to the categories clicked

查看:118
本文介绍了根据点击的类别显示不同的HTML页面标题时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为一个小项目建立一个简单的论坛。我有一个名为forum.php的页面。此页面包含一个人登录后可以看到的内容。此页面包含以下代码:



 include('  databaseconnect.php'); 

$ query = select * from Categories;

$ result = mysqli_query($ db,$ query);

while ($ row = mysqli_fetch_array($ result)){
echo ' < tr>';
echo ' < td class = leftpart>';
echo ' < h3>< a href =category.php?id>'。 $ row [' Categoryname']。
' < / a>< / h3>'。 $ row [' Categorydescription'];
echo ' < / td>' ;
echo ' < td class = rightpart>';
echo ' < a href = topic.php?id =>主题主题< / a>在10-10';
echo ' < / td>' ;
echo ' < / tr>' ;
}
$ result = $ db-> query($ query);





这是上述代码的结果: [ ^ ]





当一个人点击任何类别链接例如社区活动时,它会将他们带到名为category.php的页面。现在,在这个页面上,我希望他们能够看到为特定类别创建的主题的概述。所以使用了以下代码:



 include('  databaseconnect.php'); 

$ sql1 = SELECT Categoryid,Categoryname,Categorydescription
FROM Categories
WHERE Categoryid ='
。 mysqli_real_escape_string($ db,$ _ GET [' id'])。 ';

$ result1 = mysqli_query($ db,$ sql1);

if(!$ result1)
{
echo < font color ='Red'。< p>类别无法显示,请联系
管理员< / p>< / font>< /跨度>。 mysqli_error($分贝);
}

if(mysqli_num_rows($ result1)== 0)
{
echo < font color ='Red'。< p>此类别不存在。< / p>< /字体>中
mysqli_error($ db);
}

while($ row = mysqli_fetch_assoc($ result1))
{
echo ' < h2>''中的主题。 $ row [' Categoryname']。 ' 'Category< / h2>';
}





所以我遇到的具体问题是当我点击类别表中的任何链接时我就是得到我定义的错误是:



'此类别不存在'





因此,我尝试将categories.php页面的id更改为1,其中包括:

 <   h3  >  <   a     href   =  category.php?id = 1  

我得到了以下结果: [ ^ ]





但是当我点击健康和健身类别而不是将'健康和健身'类别中的主题作为HTML标题时,它仍然会显示'社区活动类别中的主题'。







所以我将categories.php页面的id更改为2,如下所示:

 <   h3  >  <   a     href   =  category.php?id = 2  

并且相反的结果是在两个页面上都显示健康与健身类别中的主题。结果如下:

[ ^ ]



还有其他方法可以解决这个问题修好了吗?



我尝试了什么:



1)改变id从

< a href =category.php?id =到

< a href =category.php?id = 1和

< a href =category.php?id = 1





2)更改此$ sql1 =SELECT Categoryid,Categoryname ,类别描述

FROM Categories

WHERE Categoryid ='。 mysqli_real_escape_string($ db,$ _ GET ['id'])。';



到$ sql1 =从类别中选择*



3)按照这里找到的一些步骤:



https://code.tutsplus.com/tutorials/how- to-create-a-phpmys-powered-forum-from-scratch-net-10188

解决方案

query = select * from Categories;


result = mysqli_query(


db,

I am currently in the process of building a simple forum for a small project. I have a page called forum.php. This page contains the contents that a person would see once they are logged. This page contains the following code:

include ('databaseconnect.php');

   $query = "select * from Categories";

   $result = mysqli_query($db,$query);

 while ($row = mysqli_fetch_array($result)) {
    echo '<tr>';
     echo '<td class="leftpart">';
       echo '<h3><a href="category.php?id">' . $row['Categoryname'] .
                 '</a></h3>' . $row['Categorydescription'];
       echo '</td>';
       echo '<td class="rightpart">';
          echo '<a href="topic.php?id=">Topic subject</a> at 10-10';
       echo '</td>';
    echo '</tr>';
  }
$result = $db->query($query);



This is the result of the code above: [^]


When a person clicks on any category links for example 'Community Events', it takes them to a page called category.php. Now, on this page I would like them to see an overview of the topics created for a specific category as well as. So the following code was used:

 include ('databaseconnect.php');  

      $sql1= "SELECT Categoryid, Categoryname, Categorydescription
        FROM Categories 
      WHERE Categoryid= '" . mysqli_real_escape_string($db,$_GET['id'])."'";

      $result1= mysqli_query($db,$sql1);

 if(!$result1)
   {
echo "<font color = 'Red' .<p> Category Cannot be displayed, Contact the 
      administrator </p> </font>". mysqli_error($db); 
   }

if(mysqli_num_rows($result1) == 0)
   {
    echo "<font color = 'Red' .<p>This category does not exist.</p> </font>". 
  mysqli_error($db); 
   }

 while($row = mysqli_fetch_assoc($result1))
     {
        echo '<h2>Topics in ′' . $row['Categoryname'] . '′ Category</h2>';
   }        



So the specific problem I was experiencing is when I click on any of the links in the categories table I am getting the error that I defined which is:

'This category does not exist'



So, I tried changing the "id" of the categories.php page to 1 which is the following:

<h3><a href="category.php?id=1"

and I got the following result: [^]


But when I went and click on the Health and Fitness category instead of saying 'Topics in 'Health and Fitness' Category as the HTML header it still says 'Topics in Community Events Category'.



So I changed the "id"of the categories.php page to 2 which is the following:

<h3><a href="category.php?id=2"

and the opposite resulted whereby it says 'Topics in 'Health and Fitness' Category on both pages. This is the result:
[^]

Is there any other way that this problem can be fixed?

What I have tried:

1) Changing the id to from

<a href="category.php?id=" to

<a href="category.php?id=1" and

<a href="category.php?id=1"


2) Changing this $sql1= "SELECT Categoryid, Categoryname, Categorydescription
FROM Categories
WHERE Categoryid= '" . mysqli_real_escape_string($db,$_GET['id'])."'";

to $sql1= "Select * from Categories"

3) Following some of the step found here:

https://code.tutsplus.com/tutorials/how-to-create-a-phpmysql-powered-forum-from-scratch--net-10188

解决方案

query = "select * from Categories";


result = mysqli_query(


db,


这篇关于根据点击的类别显示不同的HTML页面标题时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆