Fast question about a query
#1

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.
Reply
#2

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")  
?>
Reply
#3

Still the same.
Reply
#4

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 
Reply
#5

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?
Reply
#6

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

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.
Reply
#8

Yes now it works, thanks.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)