Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created March 15, 2012 19:45
Show Gist options
  • Save rlemon/2046387 to your computer and use it in GitHub Desktop.
Save rlemon/2046387 to your computer and use it in GitHub Desktop.

Current Output

Array
(
	[0] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 1
			[unit] => cup
			[ingredient] => lemon
			[tags] => tagX
		)

	[1] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 1
			[unit] => cup
			[ingredient] => lemon
			[tags] => tag27
		)

	[2] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 1
			[unit] => cup
			[ingredient] => lemon
			[tags] => tag6
		)

	[3] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 1
			[unit] => cup
			[ingredient] => lemon
			[tags] => tag2
		)

	[4] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 22
			[unit] => 
			[ingredient] => more nothings
			[tags] => tagX
		)

	[5] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 22
			[unit] => 
			[ingredient] => more nothings
			[tags] => tag27
		)

	[6] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 22
			[unit] => 
			[ingredient] => more nothings
			[tags] => tag6
		)

	[7] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 22
			[unit] => 
			[ingredient] => more nothings
			[tags] => tag2
		)

	[8] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 11
			[unit] => 
			[ingredient] => nothings
			[tags] => tagX
		)

	[9] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 11
			[unit] => 
			[ingredient] => nothings
			[tags] => tag27
		)

	[10] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 11
			[unit] => 
			[ingredient] => nothings
			[tags] => tag6
		)

	[11] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[amount] => 11
			[unit] => 
			[ingredient] => nothings
			[tags] => tag2
		)

	[12] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 9
			[unit] => tbsp
			[ingredient] => butter
			[tags] => tag4
		)

	[13] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 9
			[unit] => tbsp
			[ingredient] => butter
			[tags] => tag3
		)

	[14] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 9
			[unit] => tbsp
			[ingredient] => butter
			[tags] => tag2
		)

	[15] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 9
			[unit] => tbsp
			[ingredient] => butter
			[tags] => tag1
		)

	[16] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 10
			[unit] => l
			[ingredient] => milk
			[tags] => tag4
		)

	[17] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 10
			[unit] => l
			[ingredient] => milk
			[tags] => tag3
		)

	[18] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 10
			[unit] => l
			[ingredient] => milk
			[tags] => tag2
		)

	[19] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[amount] => 10
			[unit] => l
			[ingredient] => milk
			[tags] => tag1
		)

)

Desired Output

Array
(
	[0] => Array
		(
			[id] => 11
			[owner_id] => 10
			[author_id] => 10
			[name] => recipe2
			[description] => Vivamus a nisi et metus blandit hendrerit id non enim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
			[is_private] => 1
			[picture] => uploads/3c1ece0cecaba384b4c6722a596d08aa.jpg
			[prep_directions] => no time at all
			[cook_directions] => no time at all
			[post_directions] => no time taken
			[prep_time_hours] => 0
			[prep_time_minutes] => 0
			[cook_time_hours] => 0
			[cook_time_minutes] => 0
			[ingredients] => Array
							(
								[0] => Array 
									(
										[ingredient] => lemon
										[amount] => 1
										[unit] => cup
									)
								[1] => Array 
									(
										[ingredient] => nothings
										[amount] => 11
										[unit] => 
									)
								[2] => Array 
									(
										[ingredient] => more nothings
										[amount] => 22
										[unit] => 
									)
							)
			[tags] => Array
					(
						[0] => tagX
						[1] => tag2
						[2] => tag6
						[3] => tag27
					)
		)

	[1] => Array
		(
			[id] => 10
			[owner_id] => 10
			[author_id] => 10
			[name] => Recipe Title 1
			[description] => Suspendisse dictum tincidunt nisl. Nunc et nunc felis, at aliquet magna. 
			[is_private] => 1
			[picture] => uploads/7f2eb4d9b357be69bbfbd16a30e308d4.png
			[prep_directions] => prep
			[cook_directions] => cook
			[post_directions] => eat
			[prep_time_hours] => 0
			[prep_time_minutes] => 3
			[cook_time_hours] => 3
			[cook_time_minutes] => 0
			[ingredients] => Array
							(
								[0] => Array 
									(
										[ingredient] => butter
										[amount] => 9
										[unit] => tbsp
									)
								[1] => Array 
									(
										[ingredient] => milk
										[amount] => 10
										[unit] => l
									)
							)
			[tags] => Array
					(
						[0] => tag1
						[1] => tag2
						[2] => tag3
						[3] => tag4
					)
		)

)
SELECT r . * , i.amount, i.unit, i.ingredient, t.name AS 'tags'
FROM recipes AS r
LEFT JOIN ingredients_list AS i ON i.recipe_id = r.id
LEFT JOIN tags AS t ON t.id
IN (
SELECT tag_id
FROM tag_mappings
WHERE recipe_id = r.id
)
WHERE r.owner_id = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment