Product | SK/b | Stock | @@ -120,6 +121,11 @@|
+ [if file images/thumb/[item-field thumb]]
+ |
+ [item-description] | 8.14. How do I do a random display of items? -------------------------------------------- (Answered by Bill Carr) If you are using mysql (and others probably), you should be able to add "ORDER BY RAND()" to your SQL query. For example: [query list=1 sql=|SELECT * FROM products ORDER BY RAND() LIMIT 3| ] [list] [sql-param description]||
[loop-code] | [loop-alternate 3]
if scratch compare: [benchmark start=1] [benchmark]
if scratch compare eq 1: [benchmark start=1] [benchmark]
[page @@MV_PAGE@@]Again
---- end test ---
o Use [PREFIX-calc] instead of [calc] or [perl]
You can execute the same code as [calc] with [PREFIX-calc], which has
two benefits:
11. It doesn't require ITL parsing.
12. It is executed during the loop instead of after it.
The [PREFIX-calc] object has complete access to all normal embedded
Perl objects like $Values, $Carts, $Tag, and such. If you want to make
a data table (i.e. "products" or "pricing") available for access
inside of it, just do:
[perl tables="products pricing"] [/perl]
prior to list start. Now you can do something like:
[loop search="ra=yes"]
[loop-calc]
$desc = $Tag->data('products', 'description', '[loop-code]');
$link = $Tag->page('[loop-code]');
return "$link $desc ";
[/loop-calc]
[/loop]
o ADVANCED: Precompile and execute with [PREFIX-sub] and
[PREFIX-exec]
For repetitive routines, you can achieve a considerable savings in CPU
by pre-compiling your embedded Perl code.
In the "Construct Something" demo, the bar_link() routine in
catalog_before.cfg is an example of compiling the subroutine once at
catalog configuration time.
You can also compile routines at the time of the list execution with
[item-sub routine] CODE [/item-sub]. This means only one Safe
evaluation is done -- every time the [loop-exec routine] is called, it
is done fast as a call to the routine. This can be 10 times or more
faster than separate [calc] calls, or 5 times faster than separate
[PREFIX-calc] calls.
Example:
[benchmark start=1]
loop-calc:
[benchmark]
[benchmark start=1]
loop-sub and loop-exec:
[benchmark]
o ADVANCED: Execute and save with [query ...], then use an embedded
Perl routine.
You can run [query arrayref=myref sql="query"], which saves the
results of the search/query in a Perl reference. It is then available
in $Tmp->{myref}. (Of course, "myref" can be any arbitrary name.)
This is the fastest possible method to display a list.
Observe:
--- begin test code ---
[set waiting_for]os28004[/set]
[benchmark start=1] Embedded Perl
[/query]
[perl]
# Get the query results, has multiple fields
my $ary = $Tmp->{myref};
my $out = '';
foreach $line (@$ary) {
my ($sku, $price, $desc) = @$line;
if($sku eq $Scratch->{waiting_for}) {
$out .= "We were waiting for this one!!!!\n";
}
$out .= "sku: $sku price: $price description: $desc\n";
}
return $out;
[/perl]
-->
TIME: [benchmark]
[benchmark start=1] All loop
TIME: [benchmark]
--- end test code ---
o Other things that help:
o Avoid interpolate=1 when possible. A separate tag parser
must be spawned every time you do this. Many times people
use this without needing it.
o Avoid saving large values to Scratch, as these have to be
written to the users session. If you need them only for the
current page, clear at the end by using [tmp scratch_var]
contents [/tmp], which is the same as [seti scratch_var]
contents [/seti] except clears the value before the session
is written. You can also use [scratchd scratch_var] to
return the contents and delete them from the session at the
same time.
o Use the [more-list] facility to break up your large
searches. You can use them in [query ....] and [loop ...]
searches as well -- see the docs.
14. Using Interchange with Oracle
=================================
Question: should we be using the DBI ChopBlanks setting for Oracle or
is Interchange trimming trailing space from CHAR fields itself?
IC daemon user should have environment variables ORACLE_HOME and
possibly NLS_LANG set.
Mark Johnson (mark@endpoint.com) wrote this trigger on TABLE_NAME to
update the MOD_TIME column on insert or update. The user must have
been granted the RESOURCE role to create triggers. Here it is:
CREATE TRIGGER tr_modtime_for_TABLE_NAME BEFORE INSERT OR UPDATE ON
TABLE_NAME FOR EACH ROW BEGIN
new.MOD_TIME := SYSDATE; END; /
15. Using Interchange with PostgreSQL
=====================================
Make sure you have DBD::Pg installed and tested. Make sure
POSTGRES_INCLUDE and POSTGRES_LIB environment variables are set.
16. Using Interchange with MySQL
================================
Permissions. test_ databases usually special.
17. Using Interchange with Apache
=================================
Slightly modified article posted to the old minivend-users mail list.
Minivend-users is now interchange-users.
Date: Thu, 7 Sep 2000 12:08:37 -0700
From: Bill Randle