问题回应链接PHP MySQL,缺少代码

时间:2022-01-13 23:09:49

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!

我的代码遇到了问题。我想在按类别分组的一个页面上显示帖子,但我还需要帖子的标题作为实际文章的链接,到目前为止我尝试过的所有内容都已破坏。有人可以帮忙吗?我可以回复标题而不是链接!

1 个解决方案

#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.

你应该在评论中听取@Marten和@CharlesAddis的优秀建议,如果你不想使用ORM,你至少应该使用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.

我不确定帖子标题和帖子链接之间的关系是什么,如果你可以添加我可以更新答案。

#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.

你应该在评论中听取@Marten和@CharlesAddis的优秀建议,如果你不想使用ORM,你至少应该使用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.

我不确定帖子标题和帖子链接之间的关系是什么,如果你可以添加我可以更新答案。