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

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.