3

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Yeah I figured, ok I will just change it. Thanks for the help.
You're welcome - If you are interested, I'd recommend this book (which taught me the evils of GROUP_CONCAT and friends): amazon.com/Beginning-MySQL-Database-Design-Optimization/dp/…
but group_concat can be so cool..... haha. I like to use it sometimes for a quick query when i need to grab a bunch of id's
@Ascherer: It certainly has its uses. Just not as a replacement for a table :)
@Jacinto: I think you'll like it. Side note: It actually does have a real cover. Not sure why Amazon only shows the manuscript cover
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.