PDA

View Full Version : Outputting list from two functions !!


wap3
12-08-2002, 02:12 PM
Hi guys,

I got a bit of a script I am trying to do which I need your help on.
Ok what is suppose to do is output a list in the following format.

group[1][0]=newOption("Access Platform (Hydraulic Access Platforms)","../php/list_items.php?subid=1&st=0&lm=4")
group[1][1]=newOption("Aluminium Tower","../php/list_items.php?subid=11&st=0&lm=4")
group[1][2]=newOption("Chimney Rigs","../php/list_items.php?subid=2&st=0&lm=4")

group[2][3]=newOption("Acrow Props","../php/list_items.php?subid=13&st=0&lm=4")
group[2][3]=newOption("Air Conditioners","../php/list_items.php?subid=12&st=0=&lm4")

and so on . .. .

Now what I have so far prints this out:

group[1]=newOption("Access Platform (Hydraulic Access Platforms)","../php/list_items.php?subid=1&st=0&lm=4")
group[1]=newOption("Aluminium Tower","../php/list_items.php?subid=11&st=0&lm=4")
group[1]=newOption("Chimney Rigs","../php/list_items.php?subid=2&st=0&lm=4")

group[2]=newOption("Acrow Props","../php/list_items.php?subid=13&st=0&lm=4")
group[2]=newOption("Air Conditioners","../php/list_items.php?subid=12&st=0&lm=4")

But it also gives an error saying invalid foreach loop.

I am nearly there I guess but just can't figure it out completely.
I need to get rid of the error and add the extra numbers i.e. [1] so it says [1][0]
for the very first one and so on ...

This is what I have so far. Can you give me some advice or help me write it a little better.



$maincat = get_categories();
$maincount = count($maincat);

for ($i=0; $i<$maincount; $i++) {
$subcat = get_sub4_categories($i);
foreach($subcat as $res) {
echo "group[$i]=newOption(\"$res[Sub_name]\",\"../php/list_items.php?subid=$res[Sub_id]&st=0&lm=4\")<br>"; }
}


Thanks

wap3
12-09-2002, 10:48 AM
:confused:

anyone got some ideas please ??

thanks im stuck now

Kiwi
12-09-2002, 11:29 AM
I'm not sure on your exact syntax, but you need to have something like:echo "group[$i][$subcat]=newOption(\"$res[Sub_name]\",\"../php/list_items.php?subid=$res[Sub_id]&st=0&lm=4\")<br>";
I think $subcat is an array, so you want the reference to the element in $subcat that will give you your second index for your group array.