Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group_concat and then Exploding it into an Array

Tags:

php

mysql

I am group_concat a bunch of reviews from my db which turns it into something like this:

This is review 1, This is review 2

then I explode it into an array like:

$review = $row->review;
$row->review = explode(',', $review);

This works great until someone in there review adds a , then it obsoulvy no longer works. So is there a way to group_concat and put something besides a comma between them? Is there a better way of fixing this? Any ideas would be greatly appreciated.

like image 621
Jacinto Avatar asked Mar 22 '26 20:03

Jacinto


1 Answers

Yes, don't use GROUP_CONCAT. Create a subtable containing the reviews and appropriate relationships that link each review to.. whatever entities you are dealing with.

If you already have it set up like this, and are just using GROUP_CONCAT to fetch multiple reviews into a single result set... then still don't use GROUP_CONCAT. Use a subquery.

like image 134
Chris Laplante Avatar answered Mar 25 '26 09:03

Chris Laplante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!