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 Quote Link to comment Share on other sites More sharing options...
davidannis Posted June 10, 2013 Share Posted June 10, 2013 (edited) 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 June 10, 2013 by davidannis Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted June 10, 2013 Solution 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.