my_r31_baby Posted July 14, 2006 Share Posted July 14, 2006 Little backgroundI = newbiei have sessions working ok so i have my session u_pk ready to goI am setting up an online phonebook and when i do a search i get several results. The problem is that not all the info fits on screen so am only displaying <firstname> <lastname> <homephone> <email>. I want to have a link on the name or something so it can be clicked on and bring up that persons full details. Any ideas how this is done? Quote Link to comment https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/ Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 Yes, do you have some form of ID field?you would then retrieve the id from the database and make the hyperlink:<a href=fulldetails.php?contact=$id>$firstname</a>You then retrieve the id using $_GET on the page with the full details:$id = $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/#findComment-57984 Share on other sites More sharing options...
wildteen88 Posted July 14, 2006 Share Posted July 14, 2006 How are you currently getting the data out of the database? Post your code here and I'll be able to insert it in for you. However here is a quick example:[code=php:0]mysql_connect('localhost', 'user', 'pass')mysql_select_db('phonebook');$sql = 'SELECT * FROM phonebook';$results = mysql_query($sql);while($row = mysql_fetch_array($results)){ echo '<a href="file.phg?id=' . $row['id'] . '">' . $row['firstname'] . '</a> - '; echo $row['lastname'] . ' - ' . $row['homephone' . ' - ' . $row['email'] . "<br />\n";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/#findComment-57986 Share on other sites More sharing options...
my_r31_baby Posted July 14, 2006 Author Share Posted July 14, 2006 thanks guys... My apologies in advance this looks like a dogs breakfast...<?phpinclude("../db.php"); # Connects to DB $searchvariable = $_POST['search'];// LIKE 'Wr*'$query = "SELECT * FROM pb_users WHERE (((pb_users_firstname)LIKE'%$searchvariable%')OR((pb_users_lastname)LIKE'%$searchvariable%')OR((pb_users_homephone)LIKE'%$searchvariable%')OR((pb_users_state)LIKE'%$searchvariable%')OR((pb_users_postcode)LIKE'%$searchvariable%')OR((pb_users_mobilephone)LIKE'%$searchvariable%')OR((pb_users_homeaddress)LIKE'%$searchvariable%')OR((pb_users_emailaddress)LIKE'%$searchvariable%')OR((pb_users_townsub)LIKE'%$searchvariable%')OR((pb_users_website)LIKE'%$searchvariable%'))";$result = mysql_query($query); $num = mysql_num_rows( $result );?><?php while ($row = mysql_fetch_assoc($result)) { $fname = $row['pb_users_firstname']; $lname = $row['pb_users_lastname']; $emailaddress = $row['pb_users_emailaddress']; $homephone = $row['pb_users_homephone']; echo " <tr>"; echo "<td><a href='display_upk_details.php' target='_self'> $fname </a> </td>"; echo "<td>$lname</td>"; echo "<td>$homephone</td>"; echo "<td>$emailaddress</td>"; echo "</tr>"; };?> Quote Link to comment https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/#findComment-57988 Share on other sites More sharing options...
my_r31_baby Posted July 14, 2006 Author Share Posted July 14, 2006 just got it... Thanks guys... ;D<?php while ($row = mysql_fetch_assoc($result)) { $id = $row['pb_users_userid']; $fname = $row['pb_users_firstname']; $lname = $row['pb_users_lastname']; $emailaddress = $row['pb_users_emailaddress']; $homephone = $row['pb_users_homephone']; echo "<td><a href='display_upk_details.php?id=$id'>$fname</a></td>"; echo "<td>$lname</td>"; echo "<td>$homephone</td>"; echo "<td>$emailaddress</td>"; echo "</tr>"; };?><?php$id = $_GET['id'];echo " your ID is: $id";?> Quote Link to comment https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/#findComment-58002 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.