Jump to content

Leaderboard profile help! ($_GET)


Freid001

Recommended Posts

Hi

 

Below I have some php code which lists lists all the players in my MYSQL data base. I want to however use some code so that when people select the view hyperlink a window will open and display the correct users profile? Not sure how to do this? I think it may involve the $_GET function

 

Any help would be great thanks! :confused: :confused:

 

$query = "SELECT `User`, `Request`, `Attack`, `Defence`, `Won`, `Loss`, `XP` FROM `Game` ORDER BY CAST(`XP` AS SIGNED INTEGER) DESC";
$result = mysql_query($query);
echo "<table border='0'>";
echo "<tr> <th>Player</th> <th>Attack</th> <th>Defence</th> <th>Won</th> <th>Lost</th>  <th>XP</th> <th></th></tr>";
$row = mysql_fetch_assoc($result);
echo "<tr><td>"; 
        echo $row['User'];
   echo "</td><td>"; 
        echo $row['Attack'];
        echo "</td><td>"; 
        echo $row['Defence'];
        echo "</td><td>"; 
   echo $row['Won'];
        echo "</td><td>"; 
        echo $row['Loss'];
        echo "</td><td>"; 
        echo $row['XP'];
        echo "</td><td>"; 
   echo "<a href='profile-test.php'>View</a>";
        echo "</td><td>"; 
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>"; 
   echo $row['User'];
   echo "</td><td>"; 
        echo $row['Attack'];
        echo "</td><td>"; 
        echo $row['Defence'];
        echo "</td><td>"; 
   echo $row['Won'];
        echo "</td><td>"; 
        echo $row['Loss'];
        echo "</td><td>"; 
        echo $row['XP'];
        echo "</td><td>"; 
   echo "<a href='profile-test.php'>View</a>";
      echo "</td><td>"; 
      
echo "</td></tr>"; 
} 

echo "</table>";

echo "";
?>

 

MOD EDIT:

 . . . 

tags added.

Link to comment
https://forums.phpfreaks.com/topic/218557-leaderboard-profile-help-_get/
Share on other sites

You'll also want to select whatever field is being used as the primary key of the table, and use that value to create a link to script that will then pull the record from the DB based on the value. In the meantime, there's some redundancy in the code you posted.

 

See comment within:

<?php
$query = "SELECT `User`, `Request`, `Attack`, `Defence`, `Won`, `Loss`, `XP` FROM `Game` ORDER BY CAST(`XP` AS SIGNED INTEGER) DESC";
$result = mysql_query($query);
echo "<table border='0'>";
echo "<tr> <th>Player</th> <th>Attack</th> <th>Defence</th> <th>Won</th> <th>Lost</th>  <th>XP</th> <th></th></tr>";

/*
*********** THE CODE BLOCK BELOW IS UNNECESSARY **************
$row = mysql_fetch_assoc($result);
echo "<tr><td>"; 
        echo $row['User'];
   echo "</td><td>"; 
        echo $row['Attack'];
        echo "</td><td>"; 
        echo $row['Defence'];
        echo "</td><td>"; 
   echo $row['Won'];
        echo "</td><td>"; 
        echo $row['Loss'];
        echo "</td><td>"; 
        echo $row['XP'];
        echo "</td><td>"; 
   echo "<a href='profile-test.php'>View</a>";
        echo "</td><td>";
******** UNNECESSARY CODE ENDS HERE *********        */
        
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>"; 
   echo $row['User'];
   echo "</td><td>"; 
        echo $row['Attack'];
        echo "</td><td>"; 
        echo $row['Defence'];
        echo "</td><td>"; 
   echo $row['Won'];
        echo "</td><td>"; 
        echo $row['Loss'];
        echo "</td><td>"; 
        echo $row['XP'];
        echo "</td><td>"; 
   echo "<a href='profile-test.php'>View</a>";
      echo "</td><td>"; 
      
echo "</td></tr>"; 
} 

echo "</table>";

echo "";
?>

 

Example of using primary key to create link:

$query = "SELECT `id`, `name` FROM `table`";
$result = mysql_query($query);
while( $array = mysql_fetch_assoc($result) ) {
     echo "<a href=\"script_to_process_id.php?id={$array['id']}\">View record for {$array['name']}</a><br>\n";
}

////////////// Example script to process
if( isset($_GET['id']) && !empty($_GET['id']) ) {
     $id = (int) $_GET['id'];  // assumes id will be an integer, which it should
     $query = "SELECT whatever_fields_you_need FROM `table` WHERE `id` = $id";

// handled like any other database query from that point forward . . . 

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.