Jump to content


Photo

Primary keys in a hyperlink


  • Please log in to reply
4 replies to this topic

#1 my_r31_baby

my_r31_baby
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 14 July 2006 - 03:55 PM

Little background

I = newbie
i have sessions working ok so i have my session u_pk ready to go

I 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?

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 03:58 PM

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'];

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 July 2006 - 04:00 PM

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:
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";
}


#4 my_r31_baby

my_r31_baby
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 14 July 2006 - 04:04 PM

thanks guys...

My apologies in advance this looks like a dogs breakfast...

<?php
include("../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>";

};
?>

#5 my_r31_baby

my_r31_baby
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 14 July 2006 - 04:58 PM

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";
?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users