Reputation: 311
<select name="parentgroup" type="text" id="select2" onchange="this.form.submit();">
<?php
echo "<option value=\"0\">All Users</option>";
$result = mysql_query("select * from login WHERE stato=1");
while ($myresults = mysql_fetch_array($result))
{
$username = $myresults['user_name'];
echo "<option value=\"".$username."\" ";
echo $username== $parentgroupid ? " selected" : "";
echo ">".$username."</option>";
}
?>
</select>
Hi...am supposed to use the first element in <select>
which is <option value=\"0\">All Users</option>
to fetch values from a mysql database.
I want to now how you can assign this to a variable and use it just like $parentgroupid
Upvotes: 0
Views: 1716
Reputation: 107498
When you submit the form, depending on the method
specified in the form ("GET" or "POST"), the value will be in either the $_GET
or $_POST
arrays on the page to which you are submitting. You can retrieve the value by name (the name of the control):
$parentgroupid = $_GET['parentgroup'];
or
$parentgroupid = $_POST['parentgroup'];
Upvotes: 1
Reputation: 943108
When you submit the form (which presumably exists since you are referencing it from your JavaScript): Get the value from $_GET['name_of_form_control']
in the document referenced by the action
attribute of the form.
Upvotes: 1