johntigner Posted January 4, 2008 Share Posted January 4, 2008 i have a dynamic list\menu that displays one field of a recordset.. after the user makes a selection from the list how can i take the contents of another field from the same record and place it into a variable Quote Link to comment https://forums.phpfreaks.com/topic/84469-table-fields-and-dynamic-listmenu/ Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 You'll want to turn the the list into a list of links. You can then pass along a variable to identify the particular row in the database - hopefully you have a unique ID that can be used. So, to display the list, you'll have something along the lines of: <?php //you should already have something which looks at least similar to this $sql = "SELECT `id`,`otherfield` FROM `yourtable`"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($sql)){ echo '<a href="viewdetails.php?id='.$row['id'].'">'.$row['otherfield']."</a><br />\n"; } ?> Which links to a page, viewdetails.php, which would look similar to: <?php $id = (int) $_GET['id']; $sql = "SELECT * FROM `yourtable` WHERE `id`=$id"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); //display other information ?> Of course, you may wish to display the information on the same page as the list. If you were wanting to do this without reloading the page, then you should look into AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/84469-table-fields-and-dynamic-listmenu/#findComment-430354 Share on other sites More sharing options...
johntigner Posted January 4, 2008 Author Share Posted January 4, 2008 'm sorry i didnt explain myself right ... the list box wil be used to select a city name from one field ..then i need to take the city code from another field in that record and place it into a variable for further processing in another section of the form Quote Link to comment https://forums.phpfreaks.com/topic/84469-table-fields-and-dynamic-listmenu/#findComment-430356 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 You'll need AJAX for that. Take a look here for some tutorials: http://www.ajaxfreaks.com/tutorials.php The basic principle will that you will call the javascript request function (which is given in the above tutorials) using the onChange attribute of the drop down box. You'll pass along the city code of the selected city to a separate php page, which will query the database, and return the relevant information. The javascript can then update part of your form with whatever your searching for. Quote Link to comment https://forums.phpfreaks.com/topic/84469-table-fields-and-dynamic-listmenu/#findComment-430359 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.