lexs Posted February 23, 2010 Share Posted February 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 23, 2010 Share Posted February 23, 2010 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.