Unstoppable Domains

Limiting Mysql output

Spaceship Spaceship
Watch
Impact
19
Hey
Code:
PHP:
<?
$country = $_GET['country'];
$searchpass = $_GET['searchpass'];
$dbusername="zubair";
$dbpassword="";
$database= "z_game";
if ($searchpass == "aa") {
    mysql_connect(localhost, $dbusername, $dbpassword);
    @mysql_select_db($database) or die("Unable to select database");
    $sql = mysql_query("Select * From user where country  = '".$country."' ORDER BY RAND() LIMIT 3")  ;

    while ($row = mysql_fetch_assoc($sql)) {
        	echo $row['username'] . "\n" ;
echo "?\n";
	  	echo $row['health'].  "\n" ;
echo "?\n";
		echo $row['level']. "\n";
echo "?\n";
	      echo $row['money']. "\n";
echo "?\n";
    }
}
else {
echo "error\n";
}
?>
i am trying to get it to output ONLY the results where health and money are > 20
what do i do? can i just put it in in the QUERY ?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
$sql = mysql_query("
    SELECT * 
    FROM user 
    WHERE country  = '".$country."'
        AND health > 20
        AND money > 20
    ORDER BY RAND()
    LIMIT 3
");
?
 
0
•••
PHP:
<?
$country = $_GET['country'];
$searchpass = $_GET['searchpass'];
$dbusername="zubair";
$dbpassword="";
$database= "z_game";
if ($searchpass == "aa") {
    mysql_connect(localhost, $dbusername, $dbpassword);
    @mysql_select_db($database) or die("Unable to select database");
    $sql = mysql_query("Select * From user where country  = '".$country."' ORDER BY RAND() LIMIT 3")  ;

    while ($row = mysql_fetch_assoc($sql)) {
        if ($row['health'] > 20 && $row['money'] > 20) {
            echo $row['username'] . "\n" ;
            echo "?\n";
            echo $row['health'].  "\n" ;
            echo "?\n";
            echo $row['level']. "\n";
            echo "?\n";
            echo $row['money']. "\n";
            echo "?\n";
        }
    } else {
        echo "error\n";
    }
}
?>

SV, don't know if you can do that, so I did it this way..

Blah, don't use this. If you get 3 results and it doesn't display them.. :/
 
0
•••
Yes, you can. ;)
 
0
•••
SecondVersion said:
PHP:
$sql = mysql_query("
    SELECT * 
    FROM user 
    WHERE country  = '".$country."'
        AND health > 20
        AND money > 20
    ORDER BY RAND()
    LIMIT 3
");
?
its getting health and money from the db right?
 
0
•••
It's getting everything.

SELECT *
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back