Re: Databases, arrays and woes

From: Date: Thu, 30 Aug 2001 13:45:02 +0000
Subject: Re: Databases, arrays and woes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65506@lists.php.net to get a copy of this message
I think it's very simple to do it. <?php //... $result = mysql_query('SELECT * FROM my_table ORDER BY Type, "Place Name"'); for($i = 0, $prev_type = FALSE; $i < mysql_numrows($result); $i++) { $row = mysql_fetch_array($result); if ($prev_type !== $row['Type']) { // close the previous type list if any if ($prev_type !== FALSE) echo '</ul>'; // new Type list echo '<ul>' . $row['Type']; } // print out the rest of the row like : // Place Name and Place Abbr and ther link echo '<li>'.$row['place name']; echo ' <a>jump '.$row['place abbr'].'</a>'; //... } //... ?> or maybe I missed something? ----- Original Message ----- From: Kath <kath@kathweb.net> To: <php-general@lists.php.net> Sent: Thursday, August 30, 2001 3:17 PM Subject: [PHP] Databases, arrays and woes > I have a MySQL table which stores information like this: > > | Type | Place Name | Place Abbrv | > > and lets say I have data in the table like: > > Example #1: > | Office | Bill's Office | bo | > | Store | Millcreek Supply | mcs | > | Office | Harry's Office | ho | > | Store | Sam's Discount Taxidermy | sdt | > | Shipping | East Coast Distribution Facility | ecdf | > > What I'd like to do is be able to have PHP grab the information out of the > database and sort like this on a webpage: > > Type Name #1: > - Place Name (with hyperlink using the abbrv) > - Place Name (with hyperlink using the abbrv) > > Type Name #2: > - Place Name (with hyperlink using the abbrv) > - Place Name (with hyperlink using the abbrv) > > For a better illustration, using the information from Example #1: > > Example #2: > > Office > - Bill's Office (link using bo) > - Harry's Office (link using ho) > > Store > - Millcreek Supply (link using mcs) > - Sam's Discount Taxidermy (link using sdt) > > Shipping > - East Coast Distribution Facility (link using ecdf) > > So basically it has to group the common "Type" fields together and list them > together and make a hyperlink. > > What is the best way to do this? I've tried arrays, different MySQL calls, > voodoo, ouija boards and drinking, but nothing has gotten me what I need. > > btw, the information in "Type" is not a set number. There could be 2 or 200 > different "Type". (Otherwise this would be much easier and I might not have > a hangover from aforementioned drinking ;p ) > > - k > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#65506) next »