tags:

views:

30

answers:

2

I have a column called post_tags where there is sometimes one tag entry and sometimes multiple tags stored. These are separated by * symbols. I want to display these out to the screen one by one. If there were just one item inside the cell I would have used:

$query = mysql_query("SELECT post_tags FROM posts WHERE id=$id");

while ($result = mysql_fetch_assoc($query)) {
         $result['post_tags'];
}

But how can I display each entry individually when there are multiple ones in one cell (is this what the explode function is for)?

A: 

You could use explode, but you are better off constructing your database in a normalized way and using multiple rows for multiple tags.

Joseph Mastey
A: 

You should use a text-splitting function such as preg_split to split the field contents. Also, I've found on many occasions that it's faster than split or explode.

$tags_separated = preg_split('/\\*/', $result['post_tags']);
amphetamachine
Thank you very much, works great.
Jake