jeudi 26 janvier 2017

Change from MySQL Rand() to PHP random_int

We are creating a Random Number Game. We are currently using MySQL Rand() function in the below statement:

private function doPreEventStart($user) {
$row = db_fetch_item("SELECT resultid FROM ResultPackage 
    where ResultPackage.slotid like '%{$this->curSlotId}'
    and ResultPackage.PackageID like '%{$user->packageid}%'
    ORDER BY RAND() LIMIT 1");
$this->curResultId = $row['resultid'];
}

We need to change this to PHP function Random_Int. Please can someone suggest a way of doing this by altering the above code. The random number still needs to be within a certain range as you can see from the WHERE criteria in the SQL statement.




Aucun commentaire:

Enregistrer un commentaire