Posts: 3,351
Threads: 780
Joined: Jan 2010
I'm trying to show in a php page the admin who banned most players (number), currently i got this:
Код:
<?php
$PlayersBanned = mysql_query("SELECT * FROM `playerdata` WHERE `Banned` IS NULL OR `Banned` = 0 AND WHERE `Admin` > 0 ORDER BY `playerdata`.`PlayersBanned` DESC LIMIT 0, 10")
?>
But it doesn't return any nickname. If i remove "AND WHERE `Admin` > 0" i get the correct list. This query is supposed to show just admins starting from level 1.
Posts: 3,351
Threads: 780
Joined: Jan 2010
Posts: 987
Threads: 21
Joined: Nov 2012
Reputation:
0
First of all, don't use mysql_* functions, since they are deprecated, use mysqli_* or pdo functions instead.
About your problem, are you using a "while loop" while doing the fetch_array?
Posts: 3,351
Threads: 780
Joined: Jan 2010
This is the full query:
Код:
<?php
$PlayersBanned = mysql_query("SELECT * FROM `playerdata` WHERE `Banned` IS NULL OR `Banned` = 0 AND `Admin` > 0 ORDER BY `playerdata`.`PlayersBanned` DESC LIMIT 0, 10")
?>
To show:
Код:
<br><br><strong>Ban Hammers (Admins Who Banned Most)</strong>
<br><?php
while($row = mysql_fetch_array($PlayersBanned))
{
echo "<tr>";
echo "<br><td>".$row["user"]." <td>".$row["PlayersBanned"]."</td></td>";
echo "</tr>";
}
?>
<br><br>
@sammp thanks, but i already have my own code to show the list.
Posts: 4,878
Threads: 85
Joined: Jun 2007
Reputation:
0
Dont debug mysql queries in php. Use phpmyadmin or the command line to test your queries before using them in php scripts. This way you can eliminate php problems and optimize your queries without modifying and reuploading your php scripts again and again.
For the query itself, use brackets
SELECT * FROM `playerdata` WHERE (`Banned` IS NULL OR `Banned` = 0) AND `Admin` > 0 ORDER BY `playerdata`.`PlayersBanned` DESC LIMIT 0, 10
If this doesnt work its probably the database itself, as the query shouldnt cause any other problems.
Posts: 3,351
Threads: 780
Joined: Jan 2010
Yes now it works, thanks.