Page 1 of 1

foreach echo loop

Posted: Thu Aug 18, 2011 8:57 pm
by Supplement
I have this statement:


pulse.add('pid','<?php foreach( $cart_order_id as $product_id ) {
echo $product_id . ', ';}?>');

this is my ouput at the moment:

// Product ID that the user is viewing
pulse.add('pid','433, 139, 393, 107, 330, ');

What I would prefer as my output is:


pulse.add('pid','433');

pulse.add('pid','139');

pulse.add('pid','393');

pulse.add('pid','107');

pulse.add('pid','330');


i think i need to echo "pulse.add('pid'," . $productId . ");" into my foreach loop or foreach then echo pulse inside to get my desired results.. but i'm having mass trouble with the syntax. ughhh.. any help would be greatly appreciated.

8O

Re: foreach echo loop

Posted: Thu Aug 18, 2011 9:45 pm
by twinedev

Code: Select all

<?php
	foreach($cart_order_is as $product_id) {
		echo "pulse.add('pid',$product_id);\n";			
	}
?>

Re: foreach echo loop

Posted: Thu Aug 18, 2011 10:34 pm
by Supplement
the ouput turned out like this:


// Product ID that the user is viewing
pulse.add('pid','');



nothing.

=/

Re: foreach echo loop

Posted: Thu Aug 18, 2011 10:47 pm
by twinedev
yeah, if you did a direct copy and paste, I had a typo.

I mistyped $cart_order_is instead of $cart_order_id

Sorry about that, still waking up here...

Re: foreach echo loop

Posted: Thu Aug 18, 2011 11:09 pm
by Supplement
hahah.. thank you twinedev! you're amazing, i appreciate it.

; ]