0

I am trying to write a querry to pull just one playername out of a database by random,

can anyone see what I am missing please ?

open base<
    $sql="select playername from tablejollys
          where (ID % 1000) = floor(rand() * 1000)
          order by rand()
          limit 1";
        $result=mysql_query($sql);


        echo ['playername'] ;
>close base

Thanks.

2
Contributors
2
Replies
19
Views
3 Years
Discussion Span
Last Post by Kniggles
0

I think you do not need where condition, following should work

$sql="select playername from tablejollys  order by rand()  limit 1";
0

THANKS FOR HELPING,

I am just geting a blank white page with nothing now, ,
have looked into the base and have 2 records in there.
this is where i am up to just a now.

<?php

header('Access-Control-Allow-Origin: *');
$host="myhost"; // Host name 
$username="mybasename"; // Mysql username 
$password="password987"; // Mysql password 
$db_name="mybase"; // Database name 
$tbl_name="jollys"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database 
$sql="select ID from jollys  order by rand()  limit 1";
$result=mysql_query($sql);

echo $ID ;

// close MySQL connection 
mysql_close();
?>

The reason this line,

where (ID % 1000) = floor(rand() * 1000)

,was added at first was because i read sumwhere it would slow down when there were lots of records to play with ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.