Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Limiting Mysql output

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
$sql = mysql_query("
    SELECT * 
    FROM user 
    WHERE country  = '".$country."'
        AND health > 20
        AND money > 20
    ORDER BY RAND()
    LIMIT 3
");
?
 
0
Close
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
Close
Yes, you can. ;)
 
0
Close
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
Close
It's getting everything.

SELECT *
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back