Re: Databases, arrays and woes

From: Date: Thu, 30 Aug 2001 15:00:38 +0000
Subject: Re: Databases, arrays and woes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65284@lists.php.net to get a copy of this message
made that for ya, <pre> <? $lines = "| Office | ZZBill's Office | bo | | 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 |"; $lines = split("\n", $lines); $tree = array(); for ($i=0;$i<count($lines);$i++) { $line = trim($lines[$i]); $temp = split('\|', $line); $key1 = trim($temp[1]); $key2 = trim($temp[2]); $key3 = trim($temp[3]); $tree[$key1][$key2] = $key3; } echo '<hr>'; ksort($tree); var_dump($tree); echo '<hr>'; $lastplace = ''; while (list($key, $arr) = each($tree)) { if ($lastplace != $key) { echo '* ' . $key . "\n"; $lastplace = $key; } ksort($arr); while (list($pers, $plc) = each($arr)) echo "&nbsp;&nbsp;&nbsp;$pers is in <b>$plc</b>\n"; } ?> </pre> "Kath" <kath@kathweb.net> wrote in message news:015301c13156$2c273500$82e53181@resnet.sunysb.edu... > 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 >

« previous php.general (#65284) next »