On Tuesday, December 4, 2001, at 09:16 AM, Brian V Bonini wrote:
> I still can't get this to do what I want: > $bikes = array( > "Road" => array( > "Trek" => array( > "Trek 5200" => "road.php?brand=t5200" > ), > "LeMond" => array( > "Zurich" => "road.php?brand=zurich", > "Chambery" => "road.php?brand=chambery", > "Alpe d'Huez" => "road.php?brand=alpe", > "BuenosAries" => "road.php?brand=bueno", > "Tourmalet" => "road.php?brand=tourmalet" > ), > "Moots" => array( > "VaMoots" => "road.php?brand=vamoots" > ) > ), > ); > if ($cat == 'bikes') { > while (list($key, $val)=each($bikes[$sub_cat])) { > echo "<TD><IMG SRC=\"images/spacer.gif\" WIDTH=\"25\" > HEIGHT=\"1\" > ALT=\"\" BORDER=\"0\"></TD>\n"; > echo "<TD><A HREF=\"$val\" CLASS=\"menu\">$key</A></TD>\n"; (isn't $val here an array of bike models? If so you'll end up with <A HREF="[Array]" ...>) > while (list($sub_key, $sub_val) = each($val)) { > echo "<TD><A HREF=\"$sub_val\" > CLASS=\"menu\">$sub_key</a></td>\n"; > } > } > } > Are you looking for something more like this: $modelString = ""; $makeString = ""; foreach($bikes['Road'] as $make => $models) { $makeString .= " " . $make; foreach($models as $model => $link) { $modelString .= "<A HREF=\"$link\" CLASS=\"menu\">$model</A>"; } } print($makeString . "<br>\n"); print($modelString . "<br>\n"); (I don't get what you're trying to do with the table, though) -Steve > Will produce: > Trek Trek 5200 LeMond Zurich Chambery Alpe d'Huez BuenosAries Tourmalet > Moots VaMoots > as it should... > > But, I need it to produce: > Trek LeMond Moots > Trek 5200 Zurich Chambery Alpe d'Huez BuenosAries Tourmalet VaMoots > > And I need to get the value of $sub_val in the nested "while" loop to > where > $val is in the outer loop. > > I'm really stuck, any suggestions?? > > -Brian > ************** > > >> -----Original Message----- >> From: Jim Musil [mailto:[EMAIL PROTECTED]] >> Sent: Friday, November 30, 2001 5:26 PM >> To: [EMAIL PROTECTED] >> Cc: [EMAIL PROTECTED] >> Subject: RE: [PHP] Stuck on array, need a little help. >> >> >> >> >> The script is still working right, you just need to nest another >> while loop into your current while loop. >> >> Like so ... >> >> if ($cat == 'bikes' && $sub_cat != 'Road') { >> while (list($val, $key)=each($bikes[$sub_cat])) { >> >> echo "<tr><td>$val</td>"; >> >> while (list($sub_val, $sub_key) = each($key)) { >> >> >> echo "<TD><IMG SRC=\"images/spacer.gif\" WIDTH=\"25\" >> HEIGHT=\"1\" >> ALT=\"\" BORDER=\"0\"></td>\n"; >> echo "<TD><A HREF=\"$sub_key\" >> CLASS=\"menu\">$sub_val</a></td>\n"; >> >> >> } >> } >> } >> >> alternatively, if you know specifically what you want you could >> do this ... >> >> if ($cat == 'bikes' && $sub_cat != 'Road') { >> while (list($val, $key)=each($bikes[$sub_cat]["Trek"])) { >> >> >> >> echo "<TD><IMG SRC=\"images/spacer.gif\" WIDTH=\"25\" >> HEIGHT=\"1\" >> ALT=\"\" BORDER=\"0\"></td>\n"; >> echo "<TD><A HREF=\"$key\" CLASS=\"menu\">$val</a></td>\n"; >> >> >> >> } >> } >> >> >> >>> No, all that will do is reverse the placement >>> of the values. So now it prints out Array >>> and puts the item in the URL. Still the same problem. >>> >>> >>>> -----Original Message----- >>>> From: Jim Musil [mailto:[EMAIL PROTECTED]] >>>> Sent: Friday, November 30, 2001 4:54 PM >>>> To: [EMAIL PROTECTED] >>>> Cc: [EMAIL PROTECTED] >>>> Subject: Re: [PHP] Stuck on array, need a little help. >>>> >>>> >>>> Your script is working like you are asking it to ... >>>> >>>> >>>> Change ... >>>> >>>> while (list($val, $key)=each($bikes[$sub_cat])) { >>>> >>>> To ... >>>> >>>> while (list($key, $val)=each($bikes[$sub_cat])) { >>>> >>>> and it should work like you WANT it to ... >>>> >>>>> I'm stuck. $key returns "Array" how can I get at each >>>>> level of this array? >>>>> >>>>> if ($cat == 'bikes' && $sub_cat != 'Road') { >>>>> while (list($val, $key)=each($bikes[$sub_cat])) { >>>>> echo "<TD><IMG SRC=\"images/spacer.gif\" WIDTH=\"25\" >>>> HEIGHT=\"1\" >>>>> ALT=\"\" BORDER=\"0\"></TD>\n"; >>>>> echo "<TD><A HREF=\"$key\" CLASS=\"menu\">$val</A></TD>\n"; >>>>> >>>>> $bikes = array( >>>>> "Road" => array( >>>>> "Trek" => array( >>>>> "Trek 5200" => "road.php?brand=t5200" >>>>> ), >>>>> "LeMond" => array( >>>>> "Zurich" => "road.php?brand=zurich", >>>>> "Chambery" => "road.php?brand=chambery", >>>>> "Alpe d'Huez" => "road.php?brand=alpe", >>>>> "BuenosAries" => "road.php?brand=bueno", >>>>> "Tourmalet" => "road.php?brand=tourmalet" >>>>> ), >>>>> "Moots" => array( >>>>> "VaMoots" => "road.php?brand=vamoots" >>>>> ) >>>>> ), >>>>> "Mountain" => array( >>>>> "Trek" => array( >>>>> "Fuel 100" => "mountain.php?brand=tfuel90", >>>>> "Fuel 90" => "mountain.php?brand=schhg" >>>>> ), >>>>> "Klein" => array( >>>>> "bike 1" => "URL", >>>>> "bike 2" => "URL" >>>>> ), >>>>> "Gary Fisher" => array( >>>>> "bike 1" => "URL", >>>>> "bike 2" => "URL" >>>>> ), >>>>> "Moots" => array( >>>>> "bike 1" => "URL", >>>>> "bike 2" => "URL" >>>>> ) >>>>> ), >>>>> >>>>> >>>>> -- >>>>> PHP General Mailing List (http://www.php.net/) >>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>> To contact the list administrators, e-mail: >> [EMAIL PROTECTED] >>>> >>>> >>>> -- >>>> Jim Musil >>>> --------- >>>> Multimedia Programmer >>>> Nettmedia >>>> ------------- >>>> 212-629-0004 >>>> [EMAIL PROTECTED] >>>> >>>> -- >>>> PHP General Mailing List (http://www.php.net/) >>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>> To contact the list administrators, e-mail: >> [EMAIL PROTECTED] >>>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> To contact the list administrators, e-mail: php-list- >>> [EMAIL PROTECTED] >> >> >> -- >> Jim Musil >> --------- >> Multimedia Programmer >> Nettmedia >> ------------- >> 212-629-0004 >> [EMAIL PROTECTED] >> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]