SA-MP Forums Archive
Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help (/showthread.php?tid=657578)



Help - Dangjai - 10.08.2018

Hello i was making a tops list/ban list for my server website.
The List is repeating with same details with the registered users on server
PHP код:
AccID    Name    Money    Score    Kills    Death  GC
 4                    testttttt    50000    0    0    0    0
 4                    testttttt    50000    0    0    0    0
 4                    testttttt    50000    0    0    0    0
 4                    testttttt    50000    0    0    0    0 
Not showing correct details of registered players

PHP код:
 $query mysqli_query($con"SELECT reg_id, name, money, score,kills,bmoney, deaths,cookies FROM `players` ORDER BY reg_id DESC LIMIT 30;");
                        if(
mysqli_num_rows($query) > 0)
                        {
                             
$row mysqli_fetch_array($queryMYSQLI_ASSOC);
                             
$id 0;
                            while(
$id mysqli_num_rows($query))
                           {
                            echo 
"<tr><td>".$row['reg_id']."</td>";
                            echo 
"<td>".$row['name']."</td>";
                            echo 
"<td>".$row['money']."</td>";
                            echo 
"<td>".$row['score']."</td>";
                            echo 
"<td>".$row['kills']."</td>";
                            echo 
"<td>".$row['deaths']."</td>";
                            echo 
"<td>".$row['cookies']."</tr></td>";
                            
$id++;
                           }
                       }
                       else {
                              echo 
"<tr><td colspan='6'><small>There ARE NO PLAYERS REGISTERED IN SERVER DATABASE!!!</small></td></tr>";
                        }
                        
mysqli_free_result($query);
               
 
?> 
Thank you for helping!


Re: Help - NaS - 11.08.2018

You call mysqli_fetch_array only once. However, you need to call it for every row (each call gets the next row). Place it inside the while loop.


Re: Help - Dangjai - 11.08.2018

Can you give me the code ? sorry i am not very good in PHP


Re: Help - UFF - 11.08.2018

Код:
                        if(mysqli_num_rows($query) > 0) 
                        { 
                       
                           $id = 0; 
                           while($id < mysqli_num_rows($query)) 
                           { 
                           $row = mysqli_fetch_array($query, MYSQLI_ASSOC); 
                            echo "<tr><td>".$row['reg_id']."</td>"; 
                            echo "<td>".$row['name']."</td>"; 
                            echo "<td>".$row['money']."</td>"; 
                            echo "<td>".$row['score']."</td>"; 
                            echo "<td>".$row['kills']."</td>"; 
                            echo "<td>".$row['deaths']."</td>"; 
                            echo "<td>".$row['cookies']."</tr></td>"; 
                            $id++; 
                           } 
                       } 
                       else { 
                              echo "<tr><td colspan='6'><small>There ARE NO PLAYERS REGISTERED IN SERVER DATABASE!!!</small></td></tr>"; 
                        }



Re: Help - Dangjai - 11.08.2018

Quote:
Originally Posted by UFF
Посмотреть сообщение
Код:
                        if(mysqli_num_rows($query) > 0) 
                        { 
                       
                           $id = 0; 
                           while($id < mysqli_num_rows($query)) 
                           { 
                           $row = mysqli_fetch_array($query, MYSQLI_ASSOC); 
                            echo "<tr><td>".$row['reg_id']."</td>"; 
                            echo "<td>".$row['name']."</td>"; 
                            echo "<td>".$row['money']."</td>"; 
                            echo "<td>".$row['score']."</td>"; 
                            echo "<td>".$row['kills']."</td>"; 
                            echo "<td>".$row['deaths']."</td>"; 
                            echo "<td>".$row['cookies']."</tr></td>"; 
                            $id++; 
                           } 
                       } 
                       else { 
                              echo "<tr><td colspan='6'><small>There ARE NO PLAYERS REGISTERED IN SERVER DATABASE!!!</small></td></tr>"; 
                        }
Fixed!