Jump to content

drop down menu and display result


lexs

Recommended Posts

i hope this is the right place to post this, i have a drop down menu that retrieves data from a db and i use this code which works perfectly:

 

<?php
mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("abc_downloads") or die(mysql_error());
$query="SELECT name FROM series1";
$result = mysql_query($query);

echo '<select name="series1">';
while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo '<option value="' . $nt['id'] . '">' . $nt['name'] . '</option>';
/* Option values are added by looping through the array */
}
echo '</select>'; // Closing of list box
?>

 

the thing is i don't know how to send the values to a second php, depending on the selection i'd like the second php to display the results like this:

<?php
mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("abc_downloads") or die(mysql_error());

$data = mysql_query("SELECT series1.title, author.name, series1.description FROM series1, author
WHERE (series1.author_id = author.author_id) LIMIT 0 , 30")
or die(mysql_error()); 

$info = mysql_fetch_array( $data ); 
Print "<b>Title:</b> ".$info['title'] . " <br>"; 
Print "<b>Author:</b> ".$info['name'] ."<br>";
Print "<b>Description:</b> ".$info['description'] ."<br>";
?>

Please help me.

 

Link to comment
Share on other sites

On the first page you need to create a FORM. In the parameters of the form tag you need to set the action value to be the secondary page and set the method to either POST or GET (probably POST). But, there is a problem with the code you already have. The query is only capturing the name - not the ID which you are trying to use as the value in the select options. You need to change that query to caputure the ID as well

$query="SELECT id, name FROM series1";

 

Then on the secondary page you need to capture the submitted form value using either $_POST['series1'] or $_GET['series1'] and use in your query:

 

$query = "SELECT series1.title, author.name, series1.description
          FROM series1, author
          WHERE (series1.author_id = author.author_id)
            AND series1.id = {$seriesID}
          LIMIT 0 , 30";
$data = mysql_query($query);

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.