Thanks man that really works..!!... I want to ask another question can I retrieve a random row from a table? if can, could anyone tell me (using the same table and scheme from the previous question) Thanks again Mr Philipp Auersperg -IGUN- ICQ:1474584
call : <dtml-in "ShowProduct(product_id=1)">
with <let> you just define a variable in the current namespace
Philipp Auersperg (zwork)
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
participants (2)
-
Indra Gunawan -
jan@haul.de