Running ForLoops in php in another for loop

Hi all,

I am developing a shoping system and on submit of buying items from items database i am wanting to loop through items dynamically so only items that have 1 or more but not just that get the name of the items from the variable being posted.

Now the name of the field is sid and buy

so how can i run 2 for loops in between each other?

Here is my php code


  foreach ($by as $f)
			 {
				//
				if(!empty($f) && $f>0)
				{
					//
					foreach($s as $t) 
					{
						$e=getsid($t);
						echo "".$e."".$f."<br/>";
					}
					
					//
				}
			 }

What is it actually displaying is this

broken stick3
Knife3
broken stick2
Knife2

Which i only want it to display this

broken stick3
Knife3

Why what is going on how can i fix this?

Thanks,William

What makes the output you got wrong, and what makes the output you want right?

What is in $by and $s? What does getsid() do?

getsid gets the item name from database is all what that does what i want is

it only loops each item and actually print out

broken stick3
Knife3

not

broken stick3
broken stick3

or

broken stick3
Knife3
broken stick3
Knife3


foreach ($by as $f) {
    foreach($s as $t) {
        $e=getsid($t);
        echo "".$e."".$f."<br/>";
    }
}

if $by has two elements, and $s one element: “broken”, then you will two "broken"s if $by has 49 elements, you will get 49 brokens.

that code above repeats this

roken stick8
Knife8
broken stick9
Knife9
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0
broken stick0
Knife0

OK, each element in $by is a product someone wants to buy

You want to print the full name of each of those products

This does not require any nesting of loops

How do the values in array $s relate to the values in array $by? How do we know which entry in $s is the right one to use for looking up the name in $by?