Jump to content

Selecting a Value from a dynamically generated drop down box


surajkandukuri

Recommended Posts

Hi All,

 

      I am new to php scripting and write now i am stuck with my coding. I have drop down box which gets its values from mysql database, I can see correct values in the drop down box, but the problem is I AM unable to store the value selected by the user in a variable. The code is attached below.

 

        $strQuery = "select * from employees";

             

  $rsrcResult = mysql_query($strQuery);

 

  while($arrayRow = mysql_fetch_assoc($rsrcResult)) {

      $strA = $arrayRow["employee_id"];

      $strB = $arrayRow["employeename"];

      echo "<option selected='selected' value=\"$selectedvalue\">$strB</option>\n";

  }

Any help is really appreciated.

 

So you wish to store the selected value in a variable? In order to do that the form would need to be submitted (PHP is server side, so it can only see the selected value once you submit the information back to the server). You would then use either the $_POST or $_GET superglobal arrays to fetch the value based on the name attribute of the select node.

Thank you Cags!!

 

              I tried submitting the Drop down box using POST method but once the page refreshes , Drop down box becomes empty with no values in it, and also I cannot ECHO the value selected using echo($selectedvalue). I have changed the value attribute of the above code to NAME attribute

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.