Jump to content

Grouping Like Items


hadem

Recommended Posts

So i wanted to write a simple PHP script that would keep track of my recipes in a MySQL database so that I could keep track of the ingredients, any notes, and ratings, etc. I really wanted a feature where i could select a bunch of recipes and have the script generate a shopping list for me. I know how to do that, but then i want it to group like items. So, if two different recipes call for one apple, the shopping list would tell me to buy 2 apples instead of listing 1 apple twice. Does anyone have any suggestions? Thanks in advance.
Link to comment
Share on other sites

you could probably use "GROUP BY" in your query.

SELECT * FROM recipies WHERE cluause goes here GROUP BY ingrediantsTable

OR

in your PHP script that makes a list, as you go through your database results and add each item to the list, put them into an array. As you add each item to the array, do a check to see if the item is already inarray(). if so, don't add it again.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.