By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,553 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,553 IT Pros & Developers. It's quick & easy.

Usings Arrays & Multiple Filters

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1.           <input type="checkbox" name="food[]" value="6">Pork<br>
  2.      <input type="checkbox" name="food[]" value="163">Ground Beef<br>
  3.     <input type="checkbox" name="food[]" value="164">Deer Beef<br>
  4.     <input type="checkbox" name="food[]" value="165">Meat Balls<br>
  5.     <input type="checkbox" name="food[]" value="166">Roast Beef<br>
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:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="filter1"
  2.         value="$cata[]:like:$food[]" />
  4. <input type="submit" value="Update">
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: ilter2=meat2: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 :

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

Martin Curry
Jul 26 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 5,821
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:

Expand|Select|Wrap|Line Numbers
  1. <input ... name="food[{categoryID}][]" value="{subcategoryID}" />
When the User submits the form, you'll have a $_POST array that looks something like this:

Expand|Select|Wrap|Line Numbers
  1. $_POST = array(
  2.     'food'    =>    array(
  3.         '1'        =>    array(
  4.             '12'    =>    'ON',
  5.             '18'    =>    'ON'
  6.         ),
  8.         '5'        =>    array(
  9.             '48'    =>    'ON'
  10.         )
  11.     ),
  12.     .
  13.     .
  14.     .
  15. );
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.
Jul 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.