Unstoppable Domains

Get random stuff from the DB?

Spaceship Spaceship
Watch
Impact
19
Hey
i have this code which alwayz gets the FIRST three matches...is there way of making it so it gets RANDOM 3 ?
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."' 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";
}
?>
 
Last edited by a moderator:
0
•••
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."' ORDER BY RAND() LIMIT 3");
 
Last edited:
1
•••
PHP:
$sql = mysql_query("SELECT * FROM user WHERE country = '".$country."' ORDER BY RAND() LIMIT 3");
 
1
•••
lol, Dan Friedman and SecondVersion posted the exact same thing.
 
0
•••
lpxxfaintxx said:
lol, Dan Friedman and SecondVersion posted the exact same thing.
Must mean that it works, and is the right way to do it then :)

It's interesting too, because this will really help me with www.restaurantselector.net. I was using arrays and php's rand() function, but I think I will switch to this, make it much easier. rep added to these 2 guys from me!
 
0
•••
Last edited by Dan Friedman : Today at 06:57 PM.
Why the edit dan? :p
 
0
•••
I think mine was right to begin with.. I'll test what I had first. :X

edit: nope. :0 but my post is still before SV's. So I win. (.. waits for some edits..)
 
Last edited:
0
•••
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