MiniVend Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: Random item teasers?



On Thu, 24 Jun 1999, JFox MiniVend list wrote:
> Err, I'm afraid that's not quite what I want, or at least from what you
> said... I want a way for X unique, random items from the database to be
> selected and displayed. And I want them to be displayed thus:
> 
> <table>
>    <tr>
>       <td>ITEM1</td>
>       <td>ITEM2</td>
>    </tr>
>    <tr>
>       <td>ITEM3</td>
>       <td>ITEM4</td>
>    </tr>
> </table>
> 
> Is this do-able?

Anything is doable :)

I can offer an idea to get you started but no working code.  In our
ad banner server I build arrays holding all the info we need for each
banner.  This is done once at startup time.

When we need to display a banner I use the following to select which banner
to display

    gettimeofday(&tp, &tzp);
    offset = (tp.tv_usec % (count * 2)) % count;
    strcpy(url, useList[offset].linkto);
    ....

Originally I was using the time to generate a salt for random() but
that didn't work very well.  I discovered through trial and error
that the calc above provides a remarkably even distribution.  BTW, 
count is the total number of elements in the array.

The C should translate to perl line for line.

So what you need to do is write a GlobalSub that will use the above to
select an sku from an array of all skus and return that sku.  If the
array is null the GlobalSub would initialize it by doing a 
select code from products.  This would only need to be done the first
time the routine is called.  Not sure how you'd cycle through all the 
items with a dbm database.

The sub would return a link to the flypage for the sku. So..

 <table>
    <tr>
       <td>[randomsku]</td>
       <td>[randomsku]</td>
    </tr>
    <tr>
       <td>[randomsku]</td>
       <td>[randomsku]</td>
    </tr>
 </table>

That's how I'd approach it if I needed this functionality, hope this is 
enough to get you started.

Dan
-- 
 Dan Busarow                                                  949 443 4172
 Dana Point Communications, Inc.                            dan@dpcsys.com
 Dana Point, California  83 09 EF 59 E0 11 89 B4   8D 09 DB FD E1 DD 0C 82



Search for: Match: Format: Sort by: