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

Get random stuff from the DB?

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
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."' ORDER BY RAND() LIMIT 3");
 
Last edited:
1
Close
PHP:
$sql = mysql_query("SELECT * FROM user WHERE country = '".$country."' ORDER BY RAND() LIMIT 3");
 
1
Close
lol, Dan Friedman and SecondVersion posted the exact same thing.
 
0
Close
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
Close
Last edited by Dan Friedman : Today at 06:57 PM.
Why the edit dan? :p
 
0
Close
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
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

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