I want to display icons for each tag, just like Stackoverflow does.
There are 2 tables related, table_icon and table_event.
table_event is for recording the events happened, of course tags to each event; table_tag is for storing tags and icons to them.
Here's the structure of table_icon:
tag_id
tag_name
icon (an url to an img)
Here's the structure of table_event:
event_id
name
modtime
tag
In table_event, tag is stored "tag1,tag2,tag3" in tag cell.
To make it clearer, Here's an example -
Event: "Kobe Got Hurt", related tags: Kobe, Lakers, Injure
table_event:
event_id ---- 1
name -------- Kobe Bryant got hurt
modtime ----- Mar. 13, 2013
tag --------- Kobe,Lakers,injure
Corresponding table_tag: (say we have those data in table_tag before hand)
tag_id ------ 24
tag_name ---- Kobe
icon -------- .../icon/kobe.png
tag_id ------ 123
tag_name ---- Lakers
icon -------- .../icon/NBA_team_lakers.png
tag_id ------ 36
tag_name ---- injure
icon -------- .../icon/red_cross.png
This is how I extract each tag in PHP:
... // Link to Db and table and call smarty.
$t_sql = mysql_query("SELECT * FROM event WHERE 1");
$id = array();
$name = array();
$tag = array();
$icon = array();
while($t_row = mysql_fetch_array($t_sql)){
array_push($id, $t_row['event_id']);
array_push($name, $t_row['name']);
$tag_array = explode(',', $t_row['tag']);
array_push($tag, $tag_array);
// Don't know how to extract icon for each tag.
}
$smarty->assign('tid', $tid);
$smarty->assign('name', $name);
$smarty->assign('tag', $tag);
$smarty->display('event.html');
Any suggestion? Thx in advance!