Jump to content

Archived

This topic is now archived and is closed to further replies.

my_r31_baby

Primary keys in a hyperlink

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?

Share this post


Link to post
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'];

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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>";

};
?>

Share this post


Link to post
Share on other sites
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";
?>

Share this post


Link to post
Share on other sites

×

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.