How to fetch a random record from SQLite database?
Posted
by Bruce
on Stack Overflow
See other posts from Stack Overflow
or by Bruce
Published on 2010-05-29T09:30:13Z
Indexed on
2010/05/29
9:32 UTC
Read the original article
Hit count: 191
I am working on PHP. I was working with MySQL before. Here is the code I used -
$offset_result = mysqli_query($con, " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM students ");
$offset_row = mysqli_fetch_object( $offset_result );
$offset = $offset_row->offset;
$result = mysqli_query($con, " SELECT name FROM students LIMIT $offset, 1 " );
$row = mysqli_fetch_row($result);
mysqli_free_result($result);
What will be the corresponding set of statements for SQLite?
© Stack Overflow or respective owner