开发者

PHP & MySQL how to display data question

I want to be able to display my posts tags array [0] => grill [1] => meat [2] => hot-dogs with a comma separating each tag and was wondering how can I do this using PHP?

Stored in the database.

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

Desired output.

grill, meat, hot-dogs

Here is the PHP & MySQL code.

$page_tags = array();
$dbc = mysqli_query($mysqli,"SELECT tags.*, posts_tags.* 
                             FROM tags 
                             INNER JOIN posts_tags ON tags.id = posts_tags.tag_id
                             W开发者_如何学PythonHERE 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'];
    }
}


Seeing as you have an array $page_tags, you can use implode() to output it separated by commas:

echo implode(", ", $page_tags);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜