foreach echo loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Supplement
Forum Commoner
Posts: 45
Joined: Thu Aug 18, 2011 8:52 pm
Location: Oceanside, CA

foreach echo loop

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: foreach echo loop

Post by twinedev »

Code: Select all

<?php
	foreach($cart_order_is as $product_id) {
		echo "pulse.add('pid',$product_id);\n";			
	}
?>
User avatar
Supplement
Forum Commoner
Posts: 45
Joined: Thu Aug 18, 2011 8:52 pm
Location: Oceanside, CA

Re: foreach echo loop

Post by Supplement »

the ouput turned out like this:


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



nothing.

=/
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: foreach echo loop

Post 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...
User avatar
Supplement
Forum Commoner
Posts: 45
Joined: Thu Aug 18, 2011 8:52 pm
Location: Oceanside, CA

Re: foreach echo loop

Post by Supplement »

hahah.. thank you twinedev! you're amazing, i appreciate it.

; ]
Post Reply