Dicko_md Posted June 10, 2013 Share Posted June 10, 2013 $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 https://forums.phpfreaks.com/topic/278986-php-drop-down-menu-will-not-show-array-value/ Share on other sites More sharing options...
davidannis Posted June 10, 2013 Share Posted June 10, 2013 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 ! Link to comment https://forums.phpfreaks.com/topic/278986-php-drop-down-menu-will-not-show-array-value/#findComment-1435138 Share on other sites More sharing options...
mac_gyver Posted June 10, 2013 Share Posted June 10, 2013 your loop variable is $i you are just using the letter i in your code and that's not the php variable $i Link to comment https://forums.phpfreaks.com/topic/278986-php-drop-down-menu-will-not-show-array-value/#findComment-1435139 Share on other sites More sharing options...
Dicko_md Posted June 10, 2013 Author Share Posted June 10, 2013 Hi mac_gyver Thanks for that. I think I looked at it took long and missed the obvious. It works a treat now. Link to comment https://forums.phpfreaks.com/topic/278986-php-drop-down-menu-will-not-show-array-value/#findComment-1435147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.