Category 1

Category 2

Category 3

*/ // set query (you'll have to write this yourself, this is just an example) $query = "SELECT DISTINCT post_title, post_category FROM post ORDER BY post_category ASC, post_title ASC"; // run query $result = @mysql_query($query); // if rows were returned from the query if (($result) && (mysql_num_rows($result) > 0)) { // variables explained: // $current_stored_category -- this will hold the name of the category of the previous post, this will be compared to the category of the current post in order to determine if the category has changed. //$is_very_first_list -- this will be used to determine if the post in question is the very, very first post in the whole data set, if it isn't then we'll use that knowledge to print tags that will close off the list that was printed before it. // set our variables to their initial values $current_stored_category = ''; $is_very_first_list = 1; // loop and fetch all the results while ($row = mysql_fetch_assoc($result)) { $post_category = $row['post_category']; $post_title = $row['post_title']; // if this post has a different category to the one stored in $current_stored_category if ($current_stored_category <> $post_category) { // set the stored category to equal this post's category $current_stored_category = $post_category; // because we're in a new category we need to close off the last category's