954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to group two tables and fetch group by category

Hello everyone,
I have a problem with this code

php:

<?php
$sql = mysql_query("select * from news left join categories on news.category_id = categories.id group by category order by categories.id ");
while($row=mysql_fetch_array($sql)){
?>


html:

<div class="title" align="center">
<?=$row['category']?>
</div>
<div class="headlines">
<span style="float:left;"><?=$row['subject']?></span>
<span style="float:right;"> <?=$row['date']?> </span>
</div>


the problem is when i fetch array from news and categories table
i get each category has one headline
what i want to do is to include more than one news in each category

if you want more information please tell me

wetube
Newbie Poster
5 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Your GROUP BY is causing this, Try removing it and using the `category` in the ORDER BY before the `id`.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: