I am trying to get a random row from MySQL table using one of the following PHP lines:
$query = "SELECT * FROM tablename LIMIT 1 OFFSET ".rand(1,$num_rows);
$query = "SELECT * FROM tablename OFFSET RANDOM() * (SELECT COUNT(*) FROM characters) LIMIT 1";
$query = "SELECT * FROM tablename ORDER BY RAND() LIMIT 1";
but all return NULL.
Higher up my PHP code I obtain a row from the same table OK by specifying WHERE, so I don't understand why I can't retrieve a random one.
Aucun commentaire:
Enregistrer un commentaire