Jump to content

joshman13

Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Everything posted by joshman13

  1. after doing some testing, that didn't really work. the recipes will not always have 3 ingredients so i would need a dynamic way of selecting the number of ingredients that each recipe has. i changed it a little to this: SELECT recipes.*, (SELECT COUNT(*) FROM ingredients WHERE ingredients.recipe_id = recipes.id) AS ingredients_count FROM `recipes` JOIN ingredients ON (ingredients.recipe_id = recipes.id) WHERE (ingredients.product_id IN (1,2,3)) GROUP BY recipe_id HAVING ingredients_count = 3 LIMIT 1 for the most part i am still pretty new to some of the more advanced features of mysql besides your standard select statements. my question is how would a query like this effect performance? is it ok to have a select within another select or should i try to avoid something like that?
  2. so this is what i came up with: SELECT recipes.name, COUNT(*) AS ingredients_count FROM ingredients JOIN recipes ON (ingredients.recipe_id = recipes.id) WHERE ingredients.product_id IN (1,2,3) GROUP BY recipe_id HAVING ingredients_count = 3 LIMIT 1 is that what you meant? it appears to work, but i'm still playing with it some more.
  3. ah, yes. i think i will try that. initially i was using IN but since it returned records if any one of the ids matched, it was giving me problems.
  4. ok, i don't know if this is a good way of doing it but this sort of works: i find all of the selected product ids and convert it to a comma separated string like "1,2,3" and then run this: SELECT recipe_id, GROUP_CONCAT(product_id) AS product_ids FROM ingredients GROUP BY recipe_id HAVING product_ids = '1,2,3' LIMIT 1 a potential problem might be that the order of the comma separated ids might be different but it's closer to what i need at least and maybe it can help give an idea of what i am trying to accomplish.
  5. isn't that what the ingredients table is? products is a list of all of the items that can be used in a recipe and ingredients is the table that links a product to a recipe as an ingredient. the table names might be a little confusing.
  6. i am working on a relational database of recipes. i have a products table and a recipes table. i also have an ingredients table which is basically a link table between products and recipes so that basically a recipe will have many products through the ingredients table (i hope i am explaining that right). what i am trying to do is select any number of products beforehand, and then write some sort of query that will find the recipe that matches those products exactly. here is a simple schema of what i have now: products: id name recipes: id name ingredients: id product_id recipe_id so let's say i have a recipe called peanut butter and jelly. there 3 products in the products table: bread, peanut butter, and jam. so i then have 3 records in the ingredients table linking these 3 items to that recipe. i need it so that if i have fewer ingredients than the recipe calls for, nothing will be returned. or if all of the correct ingredients are used, but also the id of the ketchup product is included, that will return nothing as well. any ideas? thanks
  7. are there any drawbacks from storing all of the html markup in a variable and echoing it out to the screen as opposed to rendering the markup as it's processed? i've found several template engines that handle the output this way and i'm wondering how it works in high traffic environments.
  8. hello everyone, i am looking at building a lightweight template engine for some of my scripts that i am using. i have looked into several different ones, and although many have great features, none have exactly what i am looking for. the main thing i haven't liked is that most of them use {placeholder} style tags, which creates unnecessary overhead, because php itself is a template language, so why create a wrapper for something that already does the job? for most of the pure php template classes, this is what i've seen for the most part: : assign variables that replace content : start an output buffer : include the template file : store the rendered content of the template file in a varable : clear the output buffer : return the rendered content i really like this format just because it allows sub-templates in a main file. for instance, i can have a template file for the complete shell, but then have another file to include everytime i want a table, or a menu, or anything modular like that. i was thinking about this though, and basically the entire page is stored in a variable before the output is ever sent to the screen. are there any drawbacks to doing it this way? what about speed and memory? are there better ways to go about it?
  9. i've been offering clients complete website packages for a long time... domain name, hosting, website design, etc., so they can have a one-stop-shop basically. most of the sites that i have looked that offer the same similar thing also offer some type of ecommerce package. building a php shopping cart is prlly something that i'm capable of at this point, but that part that i have no clue about is the payment processing. i think the only thing i really know is that they'll need an ssl to encrypt the data. if anyone can shed some light on how the whole process works, including any steps through third party companies or whatever i have to do to set up automated credit processing, i would be very greatful. thanks again!
×
×
  • 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.