SA-MP Forums Archive
[PHP]Help me with get account data - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: [PHP]Help me with get account data (/showthread.php?tid=494250)



[PHP]Help me with get account data - thimo - 12.02.2014

Okay so i am trying to display the data of the player that has been clicked. Its almost working but for some reason it always just displays the name of the first person in the database. This is the code:
PHP код:
<?php
global $mysql// we are going to use mysql right? :P
if (isset($_GET['Name'])) { 
      
$page  mysqli_escape_string($mysql, (int)$_GET['Name']); // let's make sure that we just get the integer and not a attempt to do sql injection
        
$query mysqli_query($mysql"SELECT * FROM `Users` WHERE `Name` = {$page}");
        if(!
mysqli_num_rows($query)) { // if the club requested does not exists...
            
header("Location: ?p=Topscores");
            exit;
        }
        
$data mysqli_fetch_array($query); // $data['ROW_NAME'];
        
echo $data['Name'];
 } else { 
?>
    <h1>Top 20 players with the highest score</h1>
    <table width="960" border=1 frame=void rules=rows>
        <tr>
            <td>Pos.</td>
            <td>Name</td>
            <td>Score</td>
            <td>Truckloads</td>
            <td>Convoy score</td>
        <tr>
        <?php 
        $Count 
1;
        
$query mysqli_query($mysql"SELECT * FROM `Users` ORDER BY `Score` DESC LIMIT 0,100");
        while(
$row mysqli_fetch_array($query)) { 
        echo 
'
        <tr>
            <td>'
.$Count.'</td>
            <td><a href="?p=Topscores&Name='
.$row['Name'].'">'.$row["Name"].'</a></td>
            <td>'
.$row["Score"].'</td>
            <td>'
.$row["TJobs"].'</td>
            <td>'
.$row["CJobs"].'</td>
        </tr> '
;
        
$Count++; } ?>
    </table>
<?php ?>
<br><br><br>
Does anyone know why it always displays the first person in database?


Re: [PHP]Help me with get account data - kN1GhT - 12.02.2014

Код:
"SELECT * FROM `Users` ORDER BY `Score` DESC LIMIT 0,100"
u are limiting the selecting of rows to 0?


Код:
 
        $Count = 1; 
        $query = mysqli_query($mysql, "SELECT * FROM `Users` ORDER BY `Score` DESC LIMIT 0,100"); 
        while($row = mysqli_fetch_array($query)) {  
        echo ' 
        <tr> 
            <td>'.$Count.'</td> 
            <td><a href="?p=Topscores&Name='.$row['Name'].'">'.$row["Name"].'</a></td> 
            <td>'.$row["Score"].'</td> 
            <td>'.$row["TJobs"].'</td> 
            <td>'.$row["CJobs"].'</td> 

        </tr> '; 
        $Count++; }
also why are you using and incrimenting the count variable?


Re: [PHP]Help me with get account data - thimo - 12.02.2014

That is not where the problem comes from. the problem is coming from:
PHP код:
global $mysql// we are going to use mysql right? :P 
if (isset($_GET['Name'])) {  
      
$page  mysqli_escape_string($mysql, (int)$_GET['Name']); // let's make sure that we just get the integer and not a attempt to do sql injection 
        
$query mysqli_query($mysql"SELECT * FROM `Users` WHERE `Name` = {$page}"); 
        if(!
mysqli_num_rows($query)) { // if the club requested does not exists... 
            
header("Location: ?p=Topscores"); 
            exit; 
        } 
        
$data mysqli_fetch_array($query); // $data['ROW_NAME']; 

        
echo $data['Name']; 
 } else { 
?> 
For some reason it always selects the first row


Re: [PHP]Help me with get account data - Kirollos - 12.02.2014

You have to use while loop with mysqli_fetch_array

PHP код:
while($data mysqli_fetch_array($query)) // $data['ROW_NAME']; 
{
    echo 
$data['Name']; 




Re: [PHP]Help me with get account data - thimo - 12.02.2014

That echo's ALL names in the database. What i want is that when you click a name the Header changes to ?p=Topscores&Name=EXAMPE it shows the stuff about that particular account with that name.

Edit i think its in this line:
PHP код:
$page  mysqli_escape_string($mysql, (int)$_GET['Name']); // let's make sure that we just get the integer and not a attempt to do sql injection 
Because Name is not an int. I dont know how to change it though :S