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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

?>

-----

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.