With your sample code, you're storing the entire list into a variable in PHP (and it looks invalid, you'll need to put the HTML on a second line, like this):
$state_list= <<<HTML
<select name="state"> <option value="0"></option> <option value="1">ok</option> <option value="2">not-ok</option> </select>
HTML;
If you're trying to get the actual submitted value of the select list (once the form is submitted), you can access it either through $_GET['state']
, or $_POST['state']
, depending on the method your form is submitting such as:
$state = $_POST['state'];
UPDATE (outputting the form?)
From your most-recent edit, it looks like you're not putting the actual select
list inside of a <form></form>
block (which you'll need to do to actually submit the value). A simple example is like this:
echo '<form method="get">';
echo $state_list;
echo '<input type="submit" value="Submit Form" />';
echo '</form>';
I've also included a submit
-button to give you a way to, well, submit the form =P.
However, you're going to encounter an issue with this method because you need a separate select
-list for every row in your results. Because of this, you'll actually need a separate form for every row in your results (or some extra javascript code, but we'll leave that one for a rainy day).
Also, since you need a value for each individual row, you'll need a second (hidden) field to tell which row was selected. Here's a block of sample code that should be able to do this for you:
while($row = mysql_fetch_array($result1)) {
echo "<tr>";
echo "<td>" . $row['task'] . "</td>";
echo "<td>" . $row['task_desc'] . "</td>";
echo "<td>";
echo '<form method="get"><input type="hidden" name="task" value="' . $row['task'] . '" />';
echo $state_list;
echo '<input type="submit" value="Submit" /></form>';
echo "</td>";
echo "</tr>";
}
The problem with this method is that you'll have a Submit
button on every single row. While this will work and I've seen it in numerous places before, it's not really visually appealing. If this is unsuitable for your needs, you could update the select
list to auto-submit when a value is selected. To do this, just update the <select>
tag to: <select name="state" onchange="this.form.submit()">
. If you do this, you could remove the submit
-button from the output loop above.