hadem Posted May 22, 2006 Share Posted May 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10193-grouping-like-items/ Share on other sites More sharing options...
micah1701 Posted May 22, 2006 Share Posted May 22, 2006 you could probably use "GROUP BY" in your query.SELECT * FROM recipies WHERE cluause goes here GROUP BY ingrediantsTableORin 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. Quote Link to comment https://forums.phpfreaks.com/topic/10193-grouping-like-items/#findComment-37982 Share on other sites More sharing options...
hadem Posted May 23, 2006 Author Share Posted May 23, 2006 So i got it to group. i used[code]$result = mysql_query("SELECT item, SUM(qty) FROM recipes GROUP BY item");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10193-grouping-like-items/#findComment-38104 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.