You absolutely should not use a loop. MySQL is group based, as are most database management systems.
What you are trying to do is concatenate values from the
postmeta
table based on the post_id
If you look at the simple query
select A.ID, A.POST_CONTENT, B.meta_value
FROM @posts A
INNER JOIN @postmeta B ON A.ID=B.post_id
you can get the values
1 example one. image http://url_1.pl/
1 example one. image http://url_2.pl/
2 ipsum. image http://url_3.pl/
2 ipsum. image http://url_4.pl/
3 something else. image http://url_5.pl/
3 something else. image http://url_6.pl/
3 something else. image http://url_7.pl/
3 something else. image http://url_8.pl/
You can then use
MySQL GROUP_CONCAT Function[
^] to create the "list" of
meta_value
s
Which I think would look something like this (untested)
SELECT A.ID, A.POST_CONTENT,
GROUP_CONCAT(B.meta_value ORDER BY B.meta_id SEPARATOR ' ')
FROM @posts A
INNER JOIN @postmeta B ON A.ID=B.post_id
I've no idea where you are getting the CHAR(10) bit from, but this should be enough to get you started