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.

Link to comment
Share on other sites

'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

Link to comment
Share on other sites

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.

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.