[ic] Help? - Search new table from flypage

Kevin Walsh interchange-users@interchange.redhat.com
Wed May 29 16:44:01 2002


> 
> Kevin Walsh wrote: ------------
> You could do it several ways.  Here are a couple of them:
> 
>   1) A small block of Perl to split the ingredients into a list of links.
>      Each link would point at a glossary entry.
> 
>   2) A separate "ingredients" table that links each product each ingredient
>      and possibly allows reverse linking where you could search on "water"
>      and get a list of products that contain that ingredient. :-)
> 
>      The ingredients table would only need two columns (SKU and ingredient)
>      to create a many-to-many association table.
> 
>      The product page could perform a query on the ingredients table and
>      get a list appropriate for that product.  Links could be generated
>      to a glossary from there.  The glossary would look like what you
>      described as your ingredients.txt, above.
> -----------------
> 
> Thanks!
> 
> So, you're suggesting I should make a new table -in addition to glossary.txt- called ingredients.txt? Forgive me if this 
> is a simple-minded question, but if I already have a field for ingredients in products.txt - which means a list of 
> ingredients is already being generated on the product page - why is this necessary?
> 
> I actually do have the glossary listings linking to the products (eg. clicking on "water" pulls up all of the products 
> that contain that ingredient): 
> 
> <a href="[area search="se=[my-data glossary word]"]">[my-data glossary word]</a>
> 
> Now, of course, I'm attempting to turn this around so that I can get a lookup in glossary.txt from the product page. 
> 
> With my existing setup, is there a query I can run from the product page that will achieve this? (Right now really 
> wishing I could code Perl!)
> 
Ok, since you seem to have most of option 2 done, I'll discard option
1 and move on.  I'll make the following assumptions and then present
some Perl for you to try:

   1) You have a column on your products table called 'ingredients',
      which contains a coma-separated list of ingredients to display
      as links.

   2) You have a page called 'glossary.html' which will be called
      with one argument: the name of the ingredient to display.

Add this code at some appropriate place on your flypage:

    [item-calc]
        my @list = split(/\s*,\s*/,q{[item-field ingredients]});
        my $buf;
        foreach (@list){
            my $href = $Tag->area({
                href => 'glossary',
                arg => $_,
            });
            $buf .= qq{<a href="$href">$_</a><br>};
        }
        $buf;
    [/item-calc]

I've just typed that code into my email client, so you'll have to
forgive any syntax errors.  If there are errors that you can't work
out then post the messages here and I, or someone here, will make a
suggestion.

That code will loop through your 'ingredients' column and produce one
link per ingredient.  Change the HTML, encoded in the qq{...} as you
see fit.  You'll may need to change the words 'ingredients' and 'glossary'
if my assumptions were incorrect.

Your glossary.html page will be passed the ingredient, as an argument,
which you may access using the [data session arg] tag.  Your page
will then just need to look up and display the appropriate information
from your glossary table.

I hope that's of some use to you.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/