Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

dynamic dropdown in php using array and select name

I am trying to create the dynamic dropdown menu in php , taking result from array

here is the code

unction Display_Screen2()
 global $secret_question_name;

 #echo $secret_question_name[2];
 print <<< HERE
 <table border="0" width="100%" cellspacing="0" cellpadding="1">
User Secret Question

   <select name = "User_Secret_Question" tabindex="2">
     while($i=0 < 4)
     <option value = \"$secret_question_name[$i]" size="20">$secret_question_name[$i] </option>;

I do not think it ever execute the while loop,  My main object is write one  <option value ... >
and put the data from  array and to display the final dripdown menu

1 Solution
instead of the while use for

     for ($i = 0; $i < 4; $i++) {
         <option value = \"$secret_question_name[$i]" size="20">$secret_question_name[$i] </option>;


also the while is inside of the print statement so try something like this


function Display_Screen2() {

global $secret_question_name;

print       "<form>" .
      "<table border='0' width='100%' cellspacing='0' cellpadding='1'>" .
      "<tr>" .
      "<td>" .
      "User Secret Question " .
      "<select name = 'User_Secret_Question' tabindex='2'>" ;

      for ($i = 0; $i < 4; $i++) {
            print "<option value='" . $secret_question_name[$i] . "' size='20'>" . $secret_question_name[$i] ."</option>";

print       "</select>" .
      "</td>" .



Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now