我试图将标题作为链接回显,因此当点击它时,它会将用户重定向到帖子。
<?php
$sql = "SELECT title, category FROM posts ORDER BY id DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
foreach($posts as $post)
while ($list = mysql_fetch_assoc($result)) {
echo "<h2><a href='post.php?post='.$post->id.>"$list['title']"</a></h2>";
echo "<p>".$list['category']."</p>";
} ?>
答案 0 :(得分:0)
尝试用此
替换您的代码<?php
$sql = "SELECT * FROM posts ORDER BY id DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while ($post = mysql_fetch_assoc($result)) {
echo '<h2><a href="post.php?post=' . $post[id] . '">' . htmlspecialchars($post['title']) . '</a></h2>';
echo '<p>' . htmlspecialchars($post['category']) . '</p>';
} ?>
答案 1 :(得分:0)
echo "<h2><a href='post.php?post='.$post->id.>"$list['title']"</a></h2>";
尝试这样:
echo "<h2><a href='post.php?post=" . $post->id . "'>". $list["title"] . "</a></h2>";