Re: query, display and grouping.. one way works but not another

From: Date: Sat, 26 Jul 2003 14:46:46 +0000
Subject: Re: query, display and grouping.. one way works but not another
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29492@lists.php.net to get a copy of this message
Aaron Wolski wrote:
Hi Guys, Have a multiple select box. I'm trying to group columns and display records under their paired groupings. [snip]
What I'd like is to display them like: Manufactuer - Type Manufacturer - Type Manufacturer - Type I tried this code but only seems to group one TYPE and move onto the next manufacturer and group that type.: echo "<select name=\"patternThreads[]\" size=\"10\" multiple style=\"font-family:monospace;\">\n"; $query = "select t.manufacturer, t.id, t.colour, t.colourID, t.type, p.thread_index FROM kcs_threads t LEFT JOIN kcs_patternthreads p ON t.id = p.thread_index WHERE p.pattern_index = '$id' OR p.pattern_index IS NULL ORDER BY t.manufacturer, t.type";
                $thread_manufacturer = '';
                $thread_types = '';
                 $result = db_query($query);
                while($thread = db_fetch($result)) {
                                  if($thread_manufacturer !=
$thread['manufacturer']) {                                                  echo "<option value=\"\"
class=\"adminEditLink\">{$thread['manufacturer']}";
                                                $thread_manufacturer =
$thread['manufacturer'];
                                                                                }
                                 if($thread_types != $thread['type']) {                                                  echo " -
{$thread['type']}";
                                                $thread_types =
$thread['type'];
                                                                                }
                                 echo "</option>\n";
}
                echo "</select>\n";
  Any idea's where I am going wrong?
Wouldn't it just be: while($thread = db_fetch($result)) { { echo "<option value=\"\" class=\"adminEditLink\">{$thread['manufacturer']} - {$thread['type']}</option>\n"; } Although I don't see where you're setting a value for the <option> in your code. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com

« previous php.db (#29492) next »