Jump to content

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/14595-primary-keys-in-a-hyperlink/
Share on other sites

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

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