note 44938 added to function.rand
| From: | boris_n at mail dot bg | Date: | Fri, 20 Aug 2004 16:46:46 +0000 |
| Subject: | note 44938 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75003@lists.php.net to get a copy of this message | ||
to igge at netpound dot com
If you have an auto_increment (id), but you delete entries from the table, you can do the following:
SELECT COUNT(id)
FROM <table_name>
WHERE 1;
Then you fetch the result to $entries, $rand = rand(0, $entries) and the take only one entry from
the database:
SELECT *
FROM <table_name>
WHERE 1
ORDER BY
id
LIMIT $rand, 1
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44938
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44938&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44938&report=yes
Search -- http://master.php.net/manage/user-notes.php