Hi I want to make a good query to have a good array. Now for example I have this query:
SELECT DISTINCT * FROM products
LEFT OUTER JOIN product_aliases
ON product_aliases.product_id = products.id
AND product_aliases.alias = '$alias'
LEFT OUTER JOIN (product_images
LEFT OUTER JOIN product_image_votes
ON product_image_votes.product_image_id = product_images.id)
ON product_images.product_id = products.id
WHERE products.id = $id
The result is two array like this:
array(
(int) 0 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
),
'product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
)
),
(int) 1 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
),
'product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
)
)
The problem is that: I want only a unique array that contain product and for example product_images that contain in an array product_images_votes. The first problem is:
- have a unique array and not two arrays
- create array inside array in base of my left join annidate
Example of array:
array(
(int) 0 => array(
'products' => array(
'id' => '1',
'user_id' => '1',
),
'product_aliases' => array(
'id' => '1',
'product_id' => '1',
'language' => 'it',
),
'product_images' => array(
'id' => '1',
'product_id' => '1',
array('product_image_votes' => array(
'id' => '2',
'product_image_id' => '1',
'vote' => '1',
))
)
Is possible to do ? I'm working with php