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
https://forums.phpfreaks.com/topic/92922-navigating-database-records-with-php/
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

Archived

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

×
×
  • 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.