php - display tags one by one -
hi have tags in database in row called tags. separated commas.
for example, stored in database tag1,tag2,tag3
.
i want retrieve them database , display them 1 one separately , before displaying each tag, want link url.
here's doing far,
$keywords = strip_tags($blog_query_results['keywords']); //retrives tags database echo wordwrap(stripslashes($keywords), 65, "<br>",true); // prints tag1,tag2, , on.
while printing them want link tag1, tag2, , tag3 different urls.
if have string :
$tags = 'tag1,tag2,tag3';
you can use explode()
function array of tags :
$arr = explode(',', $tags);
and, then, iterate on array, build link each item -- typically, using foreach()
:
foreach ($arr $t) { echo '<a href="...">' . htmlspecialchars($t, ent_compat, 'utf-8') . '</a><br />'; }
sidenote : database's design bit wrong, if store more 1 information in single field.
if have 3 tags post, should have 3 rows (one per tag), either :
- in
tags
table, - or in join-table between
posts
,tags
tables.
Comments
Post a Comment