Darla Baker writes:
> I am trying to write a perl script that I will link to a
> graphic on my web page so that when the graphic is clicked
> it will take the user to a random favorite from my
> collection of favorite urls. I've been testing the SELECT
> statement from the mysql command line using the following
> statement:
>
> SELECT _rowid,url from favorites WHERE _rowid = ROUND(
> (RAND()*24) + 1 );
>
> Right now there are 25 entries in the table and _rowid is an
> auto_increment field. When I execute the query I get an
> empty set frequently and then occasionally it will return a
> row. What am I missing? I am running mysql 3.22.22
>
> Darla Baker
> darla@stripped
>
Hi Darla,
The above should work. Can you please include in the mail the
output from the following:
shell> mysqldump db_name favorites
Please show us also some output from the client when you execute
queries:
mysql> SELECT ROUND((RAND() * 24) + 1);
and
mysql> SELECT RAND();
couple of times.
Here is an alternative query you can try, for the meanwhile we
try to find out why the above doesn't work:
SELECT _rowid,url FROM favorites WHERE _rowid = (((RAND() * 24) % 24) + 1);
Regards,
- Jani
--
+-------------------------------------------------------------+
| TcX ____ __ _____ _____ ___ |
| /*/\*\/\*\ /*/ \*\ /*/ \*\ |*| Jani Tolonen |
| /*/ /*/ /*/ \*\_ |*| |*||*| jani@stripped |
| /*/ /*/ /*/\*\/*/ \*\|*| |*||*| Helsinki |
| /*/ /*/ /*/\*\_/*/ \*\_/*/ |*|_____ Finland |
| ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^ |
| /*/ \*\ Developers Team |
+-------------------------------------------------------------+