I was wondering how I could do this without using group_concat. Since my reviews are so long the group_concat is maxing out on them so it does not return all the reviews. The only other way I could think of doing it would be to loop the query. Just so you know there are several products and several reviews for each product. Any ideas?
$this->db->select("product.id,
product.name as name,
group_concat(user.name) as user,
group_concat(rating.overall) as overall,
group_concat(rating.description SEPARATOR '|') as review");
$this->db->join('rating', 'rating.idProduct = alcohol.id', 'LEFT');
$this->db->join('user', 'user.id = rating.idUser', 'LEFT');
$query = $this->db->get('product');
return $query->result();
output as something like this:
[0] => stdClass Object (
[name] => Product
[reviews] => Array(
[0]=> (
[user] => "cKendrick "
[overall] => "1"
[Rating] => "lalalalalala review"
)
[1] = >
(...
)
)
[1] => stdClass Object (..
UPDATE:
"SELECT product.id,
product.name as name,
category.permName as category,
subCategory.permName as subCategory,
product.permName as permName,
product.picture as picture,
user.username as username,
user.firstName as firstName,
user.lastName as lastName,
user.picture as userPicture,
rating.description as review
FROM (
SELECT *
FROM product
LIMIT ?, 30
) product
LEFT JOIN category
ON category.id = product.category
LEFT JOIN subCategory
ON subCategory.id = product.subCategory
LEFT JOIN rating
ON rating.idAlcohol = product.id
LEFT JOIN user
ON user.id = rating.idUser
ORDER BY product.lastReview desc"
How would I restrict it by its category?
Which DBAL are you using? In plain old PHP you could do it like this if you really want to use a single query –
UPDATE – I have moved the product table into a subquery to enable limiting the number of products. Note that any filtering on the products should be added to the subquery not the outer select.
UPDATE – updated query based on update to question. As you want to filter products based on category before limiting the result the joins and criteria need to be added to the subquery –