2

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 loop Commented Dec 15, 2015 at 17:38
  • 2
    Since you are concatenating the titles in your query, it won't be easy to split them later! Commented Dec 15, 2015 at 17:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.