Jump to content

[SOLVED] PHP/MySQL grouping into category


cordoprod

Recommended Posts

Hello!

I have a user management system, and i am struggling with the friends section.

 

I have a DB called friends.

The structure is like this: category, friend, friend2, friend_text, friend2_text

 

What i want to do, but can't figure out, is to list all the entries, but by grouping it into category.

 

Like this:

category1

--

friend

friend

friend

 

category2

--

friend

friend

friend

 

 

If you understand? I just want to know how the SQL is going to look like.

Link to comment
https://forums.phpfreaks.com/topic/144647-solved-phpmysql-grouping-into-category/
Share on other sites

<?php

while ($row = mysql_fetch_assoc($result)) {
    if ($last_cat != $row['category']) {
           echo "<br />" . $row['category'] . "<br />--<br />";
           $last_cat = $row['category'];
    }
    
    echo $row['friend'] . "<br />";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.