-1

I am trying to echo the title out as a link, so when it is clicked it will redirect the user to the post.

<?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>";
}  ?>
mattmill98
  • 11
  • 7

2 Answers2

0

just try to replace your code with this

<?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>';
}  ?>
M0rtiis
  • 3,676
  • 1
  • 15
  • 22
0
echo "<h2><a href='post.php?post='.$post->id.>"$list['title']"</a></h2>";

try it like this:

 echo "<h2><a href='post.php?post=" . $post->id . "'>". $list["title"] . "</a></h2>";
fsn
  • 549
  • 3
  • 11