Usings Arrays & Multiple Filters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clickncook
    New Member
    • Jul 2007
    • 1

    #1

    Usings Arrays & Multiple Filters

    I'm currently working on a website for recipes that allows users to search by ingredients they have and I'm experiencing a problem with my filtering. My site allows users to just check the checkboxes of ingredients they have. I've been in and out of every forum I can find on the internet any solution and this forum has been pretty helpful! I'm using PostNuke for my CMS & the bulk of my program is run through Pagesetter. I can get my simple commands to work but when I add multiple ingredients to my search I can't get it to filter all the categories. I have my recipes broken down in 6 different categories that go into my db, eg meats1, meats2, fruits1, fruits2 etc. Sample of the code:
    [code=html]
    <input type="checkbox" name="food[]" value="6">Pork< br>
    <input type="checkbox" name="food[]" value="163">Gro und Beef<br>
    <input type="checkbox" name="food[]" value="164">Dee r Beef<br>
    <input type="checkbox" name="food[]" value="165">Mea t Balls<br>
    <input type="checkbox" name="food[]" value="166">Roa st Beef<br>
    [/code]
    Each ingredient is stored as a number that the pagesetter module determines. I have figured out that 1-20 & 40-26 are meats and so on but can't figure out how to apply it to php to run if statements & to change $cata below for the db field that the ingredient is in, but will only be that field once per search:
    [code=html]
    <input type="hidden" name="filter1"
    value="$cata[]:like:$food[]" />

    <input type="submit" value="Update">[/code]

    The filter 1 would also need to be changed per ingredient clicked, filter2, filter3. The module pagesetter itself will use long urls to relay the info:

    http://www.clickncook. com/PostNuke/index.php?modul e=Pagesetter&fi lter1=meat1:lik e:1&filter2=mea t2:like:2

    I've been banging my head on my desk for the past month trying to figure out what I'm doing wrong, and what I need to do to correct it. Example of it can be seen at :

    Click ‘N Cook helps people find simple, healthy recipes using everyday ingredients. The catalogue of recipes is managed by GBFB’s registered dietitians.


    Sorry for the long first time post but any help, or steering in a direction is greatly appreciated.

    Martin Curry
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Martin. Welcome to TSDN!

    Let me see if I understand what you're trying to accomplish here.

    So you have a bunch of categories (Meats, Breads, etc.), and within each category are a bunch of subcategories (Hamburger Patty's [sic], Steak, etc.).

    The User can check as many boxes as he wants, including from multiple categories, and you want to list the results like this:

    For any MEAT checkboxes, only return results in the MEAT category that match the selected subcategories. For any BREAD checkboxes that were selected, only return results in the BREAD category that match the selected subcategories. And so on.

    How am I doing so far?

    The solution is actually not that bad, and it's pretty close to what you have so far:

    [code=html]
    <input ... name="food[{categoryID}][]" value="{subcate goryID}" />
    [/code]

    When the User submits the form, you'll have a $_POST array that looks something like this:

    [code=php]
    $_POST = array(
    'food' => array(
    '1' => array(
    '12' => 'ON',
    '18' => 'ON'
    ),

    '5' => array(
    '48' => 'ON'
    )
    ),
    .
    .
    .
    );
    [/code]

    Or something like that. And of course, using nested foreach loops, you can quickly build the sql query or whatever it is you need to do with this information.

    Comment

    Working...