0
 <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

2
  • 2
    Use a form and send it to an php script? Commented Aug 27, 2013 at 12:50
  • i already have a form......i need to assignthe first entry to a variable Commented Aug 27, 2013 at 13:14

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The first element in the droplist is just assigned as 'All Users' while the rest of the users are populated from the database....ihave already assigned the database entries to the variable $parentgroupid but i also need to assign the first element which is used to later to query the database and fetch diffrent values from the rest
1

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'];

6 Comments

Or $_REQUEST['parentgroup']
@rink.attendant.6: Yes, although using $_REQUEST as a catch-all is generally frowned upon due to security issues.
I agree, but in this case we don't know if they're using GET or POST.
@rink.attendant.6 Cory has compensated for this by including an example for both of the global scoped arrays
The first element in the droplist is just assigned as 'All Users' while the rest of the users are populated from the database....ihave already assigned the database entries to the variable $parentgroupid but i also need to assign the first element which is used to later to query the database and fetch diffrent values from the rest
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.