Fast question about a query -
Face9000 - 07.02.2014
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.
Re: Fast question about a query - Emmet_ - 07.02.2014
You could try:
PHP код:
<?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")
?>
Re: Fast question about a query -
Face9000 - 07.02.2014
Still the same.
Re: Fast question about a query -
sammp - 07.02.2014
Try this: (not really sure this is what you want or will work)
MySQL:
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");
while($checkAdmin = mysql_fetch_array($PlayersBaned)) {
echo $checkAdmin['PUT_FIELD_FOR_ADMIN_USERNAME_HERE'] . ":";
echo "Total Bans:" . $checkAdmin['PlayersBanned'] . ".";
} // Not sure if you do the $playersBanned bit in that
Re: Fast question about a query -
GWMPT - 07.02.2014
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?
Re: Fast question about a query -
Face9000 - 07.02.2014
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.
Re: Fast question about a query -
Mauzen - 08.02.2014
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.
Re: Fast question about a query -
Face9000 - 08.02.2014
Yes now it works, thanks.