[Zope] Fw: [Zope] Parameter in ZSQL

jan@haul.de jan@haul.de
Sun, 13 Aug 2000 19:35:06 +0200


Indra Gunawan wrote:
> 
>  Thanks man that really works..!!...
>  I want to ask another question
>  can I retrieve a random row from a table?

Yes, you can - but how is a bit dependent on your database, if
you want it to be efficient. The problem here is that SQL does
not by itseld define a rownum or similar.

If, on the other hand, you have a unique, sequential "id" column
in your table, you can use that in a SELECT statement.
Read up on SELECT in your SQL manual.

Probably, I'd do it as follows (untested, but should give you the
general idea):

in your DTML method, use an expression to get a random value
between 1 and the number of rows in your table. An SQL method
like

 SELECT count(*) AS rowcount FROM table;

gives you the total number of rows.

An expression like int(rnd()*rowcount) will give you a random
value to use in a SELECT (you'll need to define it as a parameter
or pass it in via REQUEST). You could use your current
ShowProduct for that. For the details of the random call, see
your Python manual (mine is in the office).

HTH,
Jan