SOLVED - problem with foreach

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
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

SOLVED - problem with foreach

Post by johnperkins21 »

Hey guys, I'm kind of stuck on this one for some reason. I have a function with an array that I am trying to step through to create a drop-down. But for some reason, it doesn't seem to be going through the foreach statement. It's probably something I'm doing wrong, but I can't see what it is.

Here is the function:

Code: Select all

<?php
function option_names() {
	global $selected_option;
	global $row_number;
	
	$option_name=array(0=>'','AlternatePhoto','ProductPhoto','Discount','TopCategory','Category','Personalization','LeadTime',
	'GiftCertificate','Box','StyleBlock','FeaturedItem','HiddenParam','DisplayOnly','Color','Content','Mfr','ISize','Sizes',
	'Alt','Fitting','FreeShipping','InsertItem','Keywords','NonTaxable','SizingTable','Shank','ShoeMatrix','Subscription','RichFX');
	
	sort($option_name);
	echo "<td><font face=arial,helvetica style="font-size: 8pt;" ><select name=Oname$row_number style="font-size: 8pt;">\n";
	
	foreach ($option as $option_name) {
		echo "<option value="$option"";
		if($option == $selected_option) { echo " selected"; }
		echo ">$option\n";
	}
	
	echo "</select></font></td>\n";
}
?>
I know that the function is working, it's just the foreach that isn't happening. Thanks.
Last edited by johnperkins21 on Thu Feb 26, 2004 4:13 pm, edited 1 time in total.
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

SOLVED

Post by johnperkins21 »

<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>! Never mind. I thought I tried this already, but I guess not.

I needed to change

Code: Select all

<?php
 foreach ($option as $option_name) { 
?>
to

Code: Select all

<?php
 foreach ($option_name as $option) { 
?>
I'm almost positive I tried that before and it didn't work. Oh well. Sorry.
Post Reply