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 :)

Member Avatar for diafol
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.