我尝试使用下面的代码在我的页面上添加一个链接但由于某种原因它没有显示,我已将该区域设置为粗体,这一切对我来说都是正确的。我提出了整段代码,因为我不确定它是否与我用粗体输入的代码之外的代码有关。
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Forum</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n6:default.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>ITSize</h1>
<nav id="mainnav">
<ul>
<li><a href="Index.php">Home</a></li>
<li><a href="Fourth Page.html">Register</a></li>
<li><a href="Second Page.html">Revise</a></li>
<li><a href="Forum.php">Forum</a></li>
</ul>
</nav>
</header>
<article id="main">
<br>
<br>
<?php
include_once("DBconnect.php");
$cid= $_GET['cid'];
**if (isset($_SESSION['uid'])){
$logged= " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";**
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) ==1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics .= "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr><td colspan='3'<a href='Forum.php'>Return To Forum</a>".$logged."</td></tr>";
$topics .= "<tr style='background-colour: #dddddd;'><td>Topic Title</td><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td</tr>";
while ($row = mysql_fetch_assoc($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator =$row['topic_creator'];
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a><spa class='post_info'>Posted by:".$creator." on ".$date."</span></td><td align='center'>0</td><td align='center'>".$views."</td></tr>";
$topics .="<tr><td colspan='3'></td></tr>";
}
$topics .="</table>";
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
</article>
<aside id="sidebar">
</aside>
<footer><a href="Third Page.html">My Account</a>
</footer>
</div>
</body>
</html>
答案 0 :(得分:1)
阅读完整个代码后:P发现了一些标记错误:)。
在此代码段中删除了所有错误。 现在它应该可以正常工作。
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Forum</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script>var __adobewebfontsappname__="dreamweaver"; </script>
<script src="http://use.edgefonts.net/source-sans-pro:n6:default.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>ITSize</h1>
<nav id="mainnav">
<ul>
<li><a href="Index.php">Home</a></li>
<li><a href="Fourth Page.html">Register</a></li>
<li><a href="Second Page.html">Revise</a></li>
<li><a href="Forum.php">Forum</a></li>
</ul>
</nav>
</header>
<article id="main">
<br />
<br />
<?php
require_once("DBconnect.php");
$cid = $_GET['cid'];
if (isset($_SESSION['uid'])){
$logged = " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics = "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr>
<td colspan='3'>
<a href='Forum.php'> Return To Forum </a>".$logged."</td>
</tr>";
$topics .= "<tr style='background-colour: #dddddd;'>
<td>Topic Title</td>
<td width='65' align='center'>Replies</td>
<td width='65' align='center'>Views</td>
</tr>";
while ($row = mysql_fetch_array($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
$topics .= "<tr>
<td> <a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a>
<span class='post_info'>Posted by:".$creator." on ".$date."</span>
</td>
<td align='center'>0</td>
<td align='center'>".$views."</td>
</tr>";
$topics .="<tr>
<td colspan='3'> </td>
</tr>";
}
$topics .="</table>";
echo $topics;
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
</article>
<aside id="sidebar">
</aside>
<footer><a href="Third Page.html">My Account</a>
</footer>
</div>
</body>
</html>
修改强> 代码:已更新。
答案 1 :(得分:0)
您已将变量$ logged设置为等于您的文本,然后将$ logged记录在$ topics变量中,我无法看到您输出主题的位置尝试将echo $ topics添加到您的代码中
<?php
include_once("DBconnect.php");
$cid= $_GET['cid'];
if (isset($_SESSION['uid'])){
$logged= " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) ==1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics .= "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr><td colspan='3'<a href='Forum.php'>Return To Forum</a>".$logged."</td></tr>";
$topics .= "<tr style='background-colour: #dddddd;'><td>Topic Title</td><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td</tr>";
while ($row = mysql_fetch_assoc($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator =$row['topic_creator'];
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a><spa class='post_info'>Posted by:".$creator." on ".$date."</span></td><td align='center'>0</td><td align='center'>".$views."</td></tr>";
$topics .="<tr><td colspan='3'></td></tr>";
}
$topics .="</table>";
// OUTPUT $topics HERE
echo $topics;
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
另外,只是FYI加粗似乎不适用于代码。