Jump to content

navigating database records with php


mcirl2

Recommended Posts

Hey,

 

This is probably a very dumb post but I am really struggling with it and cant find much that is of help.

 

The website I am building has profiles of users. However there will be about 20 users and each with their own profile. Each user has a unique userID. How can I create a hyperlink with will go to / display the current user profile. Is it something like this. localhost/userProfile.php?id=15

 

If anyone could help that would be great!!

 

Thanks,

 

Mike

Link to comment
Share on other sites

<?php




// Variables for navigating between previous and next record id

$previd = $id -1;
$nextid = $id +1;



// Your database connection code

$dbcnx = mysql_connect('localhost:', 'usern','pwd')
or die("Error Occurred");

mysql_selectdb("iecoadventuredb");

$query = "SELECT * FROM users WHERE ID='$id'";
$result = mysql_query($query, $dbcnx);
$row = mysql_fetch_array($result);

// Checking and displaying data

If (($id > 0) && ($id <= sizeof($row))) {

echo $row['ID'];
echo "<a href=\"page.php?id=$previd\">Previous</a>
<a href=\"page.php?id=$nextid\">Next</a>";

} else {

if ($id < 1)
{
echo "Beginning of Record Set"." ";
echo "<a href=\"page.php?id=$nextid\">Next</a>";
} 

else 

{
echo "End of Record Set"." ";
echo "<a href=\"page.php?id=$previd\">Previous</a>";
}
}
?>

 

This is my code. It s very simple but when I click on the link nothing happens. I ahve tried changing the id in the address bar but nothing happens. If I hard code a value fromt he database it will work.

 

Any ideas what Im doing wrong.

 

The whole page.php?id=3 thing baffles me. What is the id?? where does it come from?

 

Thanks for the help!

 

Mike

Link to comment
Share on other sites

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.