Afa 7heaven
Afa 7heaven

Reputation: 11

php Foreach loop group data

I need help for each loop that I would like to find the data from mysqldbx with find if data have parent category first and grouping the data with them parent and echo them out with for each loop maybe it looks like this below :

start for each loop

end theforeach loop

Example data on table

id=1,name=data1,category=1

id=2, name=data2,category=1

id=3, name=data3,category=5

id=4, name=data4,category=2

id=5, name=data5,category=5

id=6, name=data6,category=2

Upvotes: 1

Views: 410

Answers (1)

Bharti Sharma
Bharti Sharma

Reputation: 126

You can write SQL query for this table and you can order by category, i.e.

select * from your_table order by category

Then you have to do nothing with foreach loop

Upvotes: 1

Related Questions