0

hello guys,
please give me any idea about solving this problem.
I have two tables

categories:
id .... category .... parent
________________________________
1 .... general .... 0
2 .... news .... 0

news:
id .... headline .... category_id
________________________________
1 .... headline1 .... 1
2 .... headline2 .... 2
3 .... headline3 .... 2
4 .... headline4 .... 1

and I have this MYSQL code
SELECT * FROM news INNER JOIN categories ON news.category_id=categories.id group by category_id,date

now I want to fetch rows based on category
so I get result like this:

general category:
headline1
headline4

news category:
headline2
headline3

please help me with this guys :)

Edited by wetube: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0
SELECT * FROM news INNER JOIN categories ON news.category_id=categories.id ORDER BY category_id,date
//from the loop onwards...
$output ="";
$cat = "";
while($d = mysql_fetch_array($result)){
  if($d['category'] != $cat){
    if($output !="")$output .= "\n</ul>";
    $output . ="\n<h3>${d['category']}</h3>\n<ul>";    
  }
  $output .= "\n\t<li>{$d['headline']}<li>";
  $cat = $d['category'];
}
if($output != "")$output .= "\n</ul>";
...
echo $output;

Not tested - off top of head.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.