Jump to content


PHP Newbie Help - Showing Database Records As Links To A Page To Show Relevant Details

  • Please log in to reply
2 replies to this topic

#1 tooNight

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 April 2006 - 09:52 PM

Just wondering if anbody could point me in the right direction

What I currently have is list of players what I want to do is make each player a hyperlink to a page with their details on. The hyperlink would be like this [a href=\"http://www.mydomain.com/playerDetails.php?playerID=1\" target=\"_blank\"]www.mydomain.com/playerDetails.php?playerID=1[/a] and it would display the player with playerID 1. I have seen this on lots of sites and would like to know how this is done, can anybody recommend me any tutorials or write me a short script to do this.

Would be a great help if somebody could point me in the right direction :D

table players:


Cheers Leon

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 April 2006 - 10:52 PM

Overview - retrieve the passed variable, use that to retrieve record from database that matches, display record data
$player = $_GET['playerID']; // retrieve passed value
// make database connection, select database etc
$query = "SELECT * from players WHERE playerID = '$player'";
$result = mysql_query($query);

Legend has it that reading the manual never killed anyone.
My site

#3 tooNight

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 April 2006 - 04:49 PM

Still trying to get this to work can get the list of players [a href=\"http://www.squashcommunities.com/players.php\" target=\"_blank\"]here[/a] with the code below. Just cannot get playerDetails.php to display the player that I have just clicked. Whenever I click on a player it takes me to playerDetails.php but I get the message no such username. Just wondering where I am going wrong?

include 'library/config.php';
include 'library/opendb.php';

$p2=mysql_query("SELECT users.username, users.playerName FROM users") or die(mysql_error());
echo "<ol>";
while($row=mysql_fetch_assoc($p2)) {

echo "<li><a href=\"playerDetails.php?$row[username]=$row[username]\">$row[playerName]</a></li>\r\n";

echo "</ol>";

include 'library/closedb.php';    


include 'library/config.php';
include 'library/opendb.php';

$username = $_REQUEST['username'];
//this bunch of code will get you the id of the player you are looking for
//The following code will get the details from mysql table
$sql = "SELECT * FROM users WHERE username='$username'";
$query = mysql_query($sql);
if (mysql_num_rows($query) > 0) {
$row = mysql_fetch_array($query);
$name = $row['playerName'];
$town = $row['town'];
$email = $row['email'];
else { echo "No Such username"; exit; }
echo "Player Name: $name <br> Town: $town <br> Email: $email";


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users