Jump to content

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


tooNight

Recommended Posts

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:

players('playerID,playerName,country,email)

Cheers Leon
Link to comment
Share on other sites

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

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?

players.php
[code]
<?php
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';    

?>
[/code]

playerDetails.php
[code]
<?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";

?>

[/code]
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.