hey guys i have a tag table in my php/mysql project that looks like this
Table name : bt_tags
Table fileds : tid,tag
and for every story rows there is a filed named : tags
Table name: stories
table filed : tags
that saved in this field as ids
1 5 6
space between them
now problem :
when using while loop to fetch all fields in story table , the page uses 1 query to show every stories' detail but for showing tag's names , i should query another table to find names , we have ids stored in story table
now i used for loop between while loop to show tag names but im sure there is a better way to decrease page queries
how can i improve this script and show tag's names without using *for loop ?*
$result = $db->sql_query("SELECT * FROM ".STORY_TABLE." ");
while ($row = $db->sql_fetchrow($result)) {
//fetching other $vars ----
$tags_id = explode(" ",$row['tags']);
$c = count($tags_id);
for($i=1;$i<$c-1;$i++){
list($tag_name,$slug) =
$db->sql_fetchrow($db->sql_query(
'SELECT `tag`,`slug` FROM `bt_tags` WHERE `tid` = "'.tags_id[$i].'" LIMIT 1'
));
$sow_tags = '$tag_name,';
}