I am having trouble with my code. I want to display posts on one page grouped by category but I also need the titles of the posts to be links to the actual articles, everything I’ve tried so far has broken. Can anyone help? I can echo the titles just not as links!
2
-
So construct your href links in the same loopMihai– Mihai2015-12-15 17:38:27 +00:00Commented Dec 15, 2015 at 17:38
-
2Since you are concatenating the titles in your query, it won't be easy to split them later!Marten– Marten2015-12-15 17:48:32 +00:00Commented Dec 15, 2015 at 17:48
Add a comment
|
1 Answer
You should take the excellent advice from @Marten and @CharlesAddis in the comments, and if you don't want to use an ORM, you should at least use PDO.
However, to give an answer for answer's sake:
while ($row = mysqli_fetch_array($result)){
echo "<h2>".$row['category']."</h2>"."<br />";
$titles = explode(", ",$row['titles']);
foreach ($title as $t) {
echo '<a href="' . $t . '">' . $t . '</a><br>';
}
echo "<hr />";
}
I'm not sure what the relation between post titles and post links are, if you can add that I can update the answer.