我想能够用逗号分隔每个标记来显示posts-tags数组[0] => grill [1] => meat [2] => hot-dogs,我想知道如何使用PHP来实现这一点?
存储在数据库中。

$page_tags = Array ( [0] => grill [1] => meat [2] => hot-dogs )

期望输出。
grill, meat, hot-dogs

这是PHP和MySQL代码。
$page_tags = array();
$dbc = mysqli_query($mysqli,"SELECT tags.*, posts_tags.*
                             FROM tags
                             INNER JOIN posts_tags ON tags.id = posts_tags.tag_id
                             WHERE posts_tags.post_id= '" . $pageID . "'
                             AND posts_tags.user_id = '" . $userID . "'
                             GROUP BY tags.tag");

if (!$dbc) {
    print mysqli_error($mysqli);
} else {
    while($row = mysqli_fetch_array($dbc)){
        $page_tags[] = $row['tag'];
    }
}

最佳答案

鉴于您有一个数组$page_tags,您可以使用implode()以逗号分隔来输出它:

echo implode(", ", $page_tags);

关于php - PHP&MySQL如何显示数据问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3617086/

10-14 13:00
查看更多