d-machine
08-10-2008, 08:20 PM
Hi
I have 2 tables, which were created in order to save stories in categories:
stories:
1) story_id
2) story_category (works as category id)
stories_categories :
1) story_categoryname
2) story_category (works also as category id)
I've tried to print the information in this way:
story_categoryname:
1) story_id
2) story_id
3)story_id
other story_categoryname:
1) story_id
2) story_id
if some category is empty and doesn't have stories it won't be printed.
this the code I've tried and didn't get where I went wrong:
$query1 = "select distinct story_categoryname from stories_categories";
$res1 = mysql_query($query1);
if($res1){
while($cat = mysql_fetch_assoc($res1)){
echo $cat['story_categoryname']."<br/>";
$query2 = "select story_id from stories where story_category in (select story_category from stories_categories where story_categoryname = '".$cat['story_categoryname']."')";
$res2 = mysql_query($query2);
if($res2){
while($story_id = mysql_fetch_assoc($res2)){
echo $story['$story_id'].'<br/>';
}
}
}
}else{
print mysql_error();
}
Thank you
I have 2 tables, which were created in order to save stories in categories:
stories:
1) story_id
2) story_category (works as category id)
stories_categories :
1) story_categoryname
2) story_category (works also as category id)
I've tried to print the information in this way:
story_categoryname:
1) story_id
2) story_id
3)story_id
other story_categoryname:
1) story_id
2) story_id
if some category is empty and doesn't have stories it won't be printed.
this the code I've tried and didn't get where I went wrong:
$query1 = "select distinct story_categoryname from stories_categories";
$res1 = mysql_query($query1);
if($res1){
while($cat = mysql_fetch_assoc($res1)){
echo $cat['story_categoryname']."<br/>";
$query2 = "select story_id from stories where story_category in (select story_category from stories_categories where story_categoryname = '".$cat['story_categoryname']."')";
$res2 = mysql_query($query2);
if($res2){
while($story_id = mysql_fetch_assoc($res2)){
echo $story['$story_id'].'<br/>';
}
}
}
}else{
print mysql_error();
}
Thank you