Re: formatting logic

From: Date: Thu, 21 Apr 2005 18:27:50 +0000
Subject: Re: formatting logic
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-213600@lists.php.net to get a copy of this message
I am allowing our members to upload pictures and they can choose which category the pictures go under, the first category "public" is made for them. When I sql the DB I call it like this: select picture_names<,more fields> from <table> where member_id=<x> order by category. which i display something like this: __________________________________ | pic-here | <some text here> | category here| | pic-here | <some text here> | category here| --------------------------------------------- how can i display it like this: __________________________________
category here                                                |
---------------------------------------------
| pic-here | <some text here>                         |
| pic-here | <some text here>                         |
__________________________________
category here                                                |
---------------------------------------------
| pic-here | <some text here>                         |
| pic-here | <some text here>                         |
--------------------------------------------- I thought of just getting the categories into an array and then sqling on each category but if there are 30 user defined categories that would mean 30 queries.... Another more complicated way would be to get all the records and sort them into arrays via categories and child arrays...I just feel this is too complicated for the above job.
Keep your query like it is... and do something like this: $current_category = ""; while ( $row = db_get_object_function($db_result) ) { if ($current_category != $row->category) { print("$row->category header goes here"); $current_category = $row->category; } print("pic-here stuff goes here"); }

« previous php.general (#213600) next »