Jump to content

Dropdown list from mysql with re-direction on select option


Cornhusker40

Recommended Posts

Hi,  I'm a php newbie, with some mysql experience. I have a mysql database as follows:

Database=watch, Table=events - fields id, reportno, sdate, comments

 

What I need is:

1. A dropdown list to display reportno from mysql database.

2. Depending on which reportno I choose, I'd like to open a popup(or separate) page to display the stored information.

 

Tks in advance for any help

 

No need to go to a different page.  Just query DB based on POSTED record id from a selection form and display record below selection area.  You can use a submit button or an onchange event to submit form.  A popup or redirect can be done if you really want that as well.  Start by making the selection form and then a few tests to query DB table based on selected value.  Should be simple enough, just do it a step at a time with little tests.

I'm lost!! Here us the code I'm using to gather the data, where do I add the onChange please?

tks

-----<?php

mysql_connect("localhost", "username", "password") or die(mysql_error());

mysql_select_db("DARABASE") or die(mysql_error());

 

$query="SELECT reportno FROM TABLE";

 

/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */

 

$result = mysql_query ($query);

echo "<select reportno=event value=''>Report No.</option>";

// printing the list box select command

 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

 

echo "<option value=$nt[id]>$nt[reportno]</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

-----

See how this works for you.

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("DARABASE") or die(mysql_error());
$query="SELECT reportno FROM TABLE";
echo '<form id="selectform" action="" method="post">';
$result = mysql_query ($query);
echo "<select reportno=\"event\" onchange=\"this.form.submit()\">";
echo "<option value=\"\">-Select-</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=\"{$nt['reportno']}\">{$nt['reportno']}</option>";
}
echo "</select>";// Closing of list box
echo "</form>";
?>

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.