Again, I am no programmer though I have to force myself into this avenue sometimes.
I showed before how to display the latest row in a MySQL database. Now I have to display a random row.
There are a bunch of ways of doing this. In my research, I found a bunch of ways and here are a few ways to select a random row from a database table:
SELECT * FROM `layouts` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `layouts` ) ORDER BY id LIMIT 1
So in my application I used it like this:
<? $sql = “SELECT * FROM `entries` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `entries` ) ORDER BY id LIMIT 1″;
$rs = $db->Execute( $sql );
?>
<h2><?=$rs->fields['title']?></h2> path/to/<?=$rs->fields['thumbnail']?>
Posted on Tuesday, August 7, 2007 by Carl Thomas / Affiliate Preacher |
Comments(0)



trackback from now on. I joined the 





Categories