
Phil’s Diary - [Blog @ http://www.philsdiary.net/]
For my birthday my parents bought me a book containing a good few hundred smoothie and juice recipes. It’s a very good book, with one exception; there’s no index by ingredient. So if I want to find all the recipes with pineapple in, I’m a bit stuck.
So last night I put together a little webapp that does just that. It took me about 10minutes to write and about an hour and a half to enter the data into the database.
It only works based on one model at the moment. You select an ingredient or a few, and it’ll tell you which recipes use all of those ingredients.
So for example if you select pineapple and lime, it’ll tell you three recipes that contain those two items (and a few other ingredients).
The obvious next step is for me to tell it all the ingredients I have to hand and for it to then tell me all the possible recipes.
Also as the data in the book is copyright, and I’m too lazy, all I did was enter into the database an id for each ingredient and the page number. I guess it might be even more useful if I included quantities, and if I included instructions as well, then I’d not need the book. But that would be quite naughty.
The beauty of using a database in this case isn’t the way the data is stored but the way I can programmatically build the quite long queries.
The database structure is such that there are 7 ingredients slots, each can contain an id of an ingredient. Now obviously if I select pineapple, I need to check each of those 7 slots to see if they have pineapple. And for each other ingredient I also need to check each of the 7 slots. As you can imagine, that’d be a pain to write with ‘ifs’, selects and so on. So instead I run a couple of line for-loop, that for each ingredient selected adds a line to the SQL query checking each of those slots.
Anyway, far too much detail there (most of it for my own future reference), suffice to say it’s very useful to me.
Posted by Phil on April 04, 2004 09:27 AM | Categories: Technology
...is illegal, you probably may not read the original more than once...
Posted by: sjon at April 5, 2004 9:47 AM
and by the time actually copying it to your comp
Posted by: sjon at April 5, 2004 9:43 AM
then I?d not need the book. But that would be quite naughty.
Not if you don't post it. Not yet anyway.
Posted by: sjon at April 5, 2004 8:39 AM