designaire Posted February 19, 2008 Share Posted February 19, 2008 I'm new to PHP. Thanks for your help in advance. I have a list of id numbers displayed on the page coming from the database. I want to be able to click on an ID number which is a link, and the other information in the database associated with that ID number is displayed 0001 I want to click on the ID number and get the information from that number 0001 John Smith 47 Smith Lane New York, NY 45514 Quote Link to comment Share on other sites More sharing options...
micah1701 Posted February 19, 2008 Share Posted February 19, 2008 this is going to involve a number of steps, 1) if you want the data to just "appear" then you're going to need to use javascript and, more specificly, AJAX. This isn't the forum to learn that. 2) once you pass the value you want to look up to a PHP script (using javascript or through some other means) you can look up the information like this: <?php $id = $_GET['idNumber']; //assign your ID number to variable (in this case, $id now equals 00001) $query = mysql_query("SELECT * FROM databasename.table_name WHERE id = '$id' "); $result_array = mysql_fetch_assoc($query); echo $result_array['name_column_in_table'] . "<br>\n"; echo $result_array['address_column_in_table'] . "<br>\n"; echo $result_array['city_column_in_table'].", " . $result_array['state'] . " " . $result_array['zipcode']; ?> 3) there's your result, so use javascript or whatever to put it where you want it to "appear" Quote Link to comment Share on other sites More sharing options...
suttercain Posted February 19, 2008 Share Posted February 19, 2008 Micha is right if you want to use more of an "AJAX" approach. I think that may be a little more than you are looking for though. Quote Link to comment Share on other sites More sharing options...
craygo Posted February 19, 2008 Share Posted February 19, 2008 pretty simple first question. You want the info to be on the same page or do you want it to go to another page. Either way here is a quick sample <?php // connect to database below //query the table $sql = "SELECT * FROM tablename"; $res = mysql_query($sql) or die(mysql_error()); // loop through the data and display the link while($r=mysql_fetch_assoc($res)){ // create link to details page echo "<a href=\"details.php?id=".$r['id']."\">$r['name']</a><br>\n"; } ?> now you will have a link to details.php passing the id number. On details.php you get the id and pass it to the query <?php $id = $_GET['id']; $sql = "SELECT * FROM table WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); echo $r['firstname']." ".$r['lastname']; ?> Hope that helps ray Quote Link to comment Share on other sites More sharing options...
marcus Posted February 19, 2008 Share Posted February 19, 2008 Of course you can continue onto Ray's code and make sure the id does exist. Quote Link to comment Share on other sites More sharing options...
designaire Posted February 19, 2008 Author Share Posted February 19, 2008 It doesn't just have to appear, it can appear on another page with another click etc.. This might be enough for me to work with until I get stuck again. Thanks for your speedy response. Quote Link to comment Share on other sites More sharing options...
designaire Posted March 4, 2008 Author Share Posted March 4, 2008 I'm not sure I ever thanked you for that answer. It worked well!! 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.