i have specific request related to slideshow on test page here:
http://bybyweb.com/mealbook/
All the big pictures should be an image from a random category, with three recipes from that category listed in text.
Small thumbnails should show random recipes from any category.
So, there should be 3 random categories, 12 recipes from these categories (grouped by 4), AND 9 random recipes, unrelated to the rest…
Database scheme:
category: id, title, parent_id
category_to_recipe: id, rec_id, cat_id (this table is there because recipe can be in more than one category)
recipes: id, name, etc, etc…
this query:
SELECT category_recipe.rec_id, category_recipe.cat_id, recipes.name, recipes.url, recipes.main_image, categories.id, categories.title
FROM recipes, category_recipe, categories
WHERE categories.id
IN ( 10, 30, 64 )
AND category_recipe.cat_id = categories.id
AND category_recipe.rec_id = recipes.id
ORDER BY RAND( )
LIMIT 12
returns 12 random recipes from 3 categories, but i need 4 recipes per category…
I guess that there are more possible solutions, and i will probably need nested selects, or something….
I think you need
union allfor this:In addition, you should use ANSI standard join syntax. Your queries would also be more readable by using aliases.