Jump to content

table fields and dynamic list\menu


johntigner

Recommended Posts

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.

'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

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.

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.