Jump to content

PHP Drop Down menu will not show array value?


Dicko_md
Go to solution Solved by mac_gyver,

Recommended Posts

$array = array("3", "6", "12", "18", "24");

$opt = '';
	for ($i=0; $i<sizeof($array); $i++) $opt .= "<option value='$array[i]'> $array[i] </option>";
	$html = "
		<form method='get' action='index.php?s=upgrade'>
		<input type='hidden' name='s' value='upgrade' />
		<input type='hidden' name='memid' value='$_GET[memid]' />
		<span class='formlabel'>Months:</span> <select name='nummonths'>$opt</select> 
<input type='submit' class='button' value=' Submit ' name='gopay'>
		<br /><br />
		</form>
	";

The above code should show 3, 6, 12, 18, 24 in a drop down menu but it is only showing 5 blank spaces.

 

Can anyone spot what I have done wrong ? If I put anyMonths in the $array between the options like below theMonths shows up on all 5 lines of the drop down

$opt .= "<option value='$array[i]'> $array[i] Months </option>";

Thanks 

 

Martyn

Link to comment
Share on other sites

try putting the variable in curly braces

{$array[i]}

from the php echo page examples:

 

// You can also use arrays
$baz = array("value" => "foo");

echo 
"this is {$baz['value']} !"// this is foo !

Edited by davidannis
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.