getting the data from a drop down menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hwttdz
Forum Newbie
Posts: 7
Joined: Wed May 25, 2005 7:48 am

getting the data from a drop down menu

Post by hwttdz »

I have a sequence of drop down menus but I don't know how I can store the responses in other variables. Right now the output I'm getting looks like

location1 [status1] [change]
location2 [status2] [change]
location3 [status3] [change]
.
.
.
.

where all the [status] are drop down menus and the [change] is a submit box. I'd like to use the change button to change the status of the location in the mysql database. How can I at least get my hands on the location that they modified and the new status of that location?

Code: Select all

<?php
$link = @mysql_connect('localhost', 'root', 'password') or 
    die(&quote;Could not connect to MySQL&quote;);

$db = @mysql_select_db('temp1',$link) or 
    die(&quote;Could not select database&quote;);

$query = &quote;SELECT * FROM table1&quote;; 
$result = @mysql_query($query,$link) or 
    die(&quote;Could not submit query&quote;);
$numrows = @mysql_num_rows($result);

for ($i=0; $i<$numrows; $i++) 
 {
    $infov = mysql_fetch_array($result);
    print (&quote;Location: &quote;.&quote;$infov&#1111;location]&quote;);
    echo(&quote;$i&quote;);
    dropmenu($infov);
    echo('<br>');
    
 }
exit(&quote;bye&quote;);
?>


<?php
function dropmenu($vector)
{
?>

<SELECT NAME=&quote;state&quote; SIZE=&quote;1&quote;>
  <OPTION <?php other($vector,1) ?> VALUE=&quote;1&quote;>ACTIVE</OPTION>
  <OPTION <?php other($vector,2) ?> VALUE=&quote;2&quote;>BROKEN</OPTION>
  <OPTION <?php other($vector,3) ?> VALUE=&quote;3&quote;&quote;>PLANNED</OPTION>
</SELECT>

<input type=&quote;submit&quote; value=&quote;change&quote;/>
<?php
echo(&quote;$vector&#1111;status]&quote;);
}
?>

<?php
function other($vector,$int)
{
if($vector&#1111;status]==$int)
{
echo('selected');
}
}
?>
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Hopefully I understand your question...

Try this:

Code: Select all

<?php
if ($Submit == "Submit")
{
	foreach ($my_list as $update_list)
	{
		echo "\$update_list:$update_list<br>";
	} //foreach ($my_list as $update_list)
} //if ($Submit == "Submit")
?>
<form name="form1" method="post" action="">
  <select name="my_list[]" size="5" multiple id="my_list[]">
    <option value="1">My Value 1</option>
    <option value="2">My Value 2</option>
  </select>
  <input type="submit" name="Submit" value="Submit">
</form>
In the for loop you can actually update the database for example
hwttdz
Forum Newbie
Posts: 7
Joined: Wed May 25, 2005 7:48 am

Post by hwttdz »

What I'm trying to do is if someone were to change the status of location2 for example I'd like to be able to 1) know that they hit the change button next to location2. 2) know what the new value of status2 is. 3) change the value of status2 stored in the database to the value of status2 selected.

location1 [status1] [change]
location2 [status2] [change]
location3 [status3] [change]
.
.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

I think a select menu won't cut it then.

Show the values in a table, with a check box[], and a button next to each one
(button[<?php echo $value_id; ?>])

So if the user clicks on the button, the button value will match the value sent so that you can update the correct value.
Post Reply