0

Can I use group_concat() function to retrieve image from the database?

Using it the images are displayed as broken because maybe it's not reading image name properly?

$sql="SELECT product.*, group_concat(images.image) as imag FROM product LEFT JOIN images on product.id=images.pid group by product.id";

the loop for displaying image:

foreach(explode('.',$row['imag']) as $url)
 {?>

   <td><?php  $imageURL = 'pictures/'.$url;?>
   <img src="<?php echo $imageURL; ?>" alt="" width="100" height="100" /></td>

   <?php
}

This is what I'm getting as output:

output

Daniele Santi
  • 771
  • 3
  • 24
  • 31
  • You need comma insteas of dot here - `explode(',',$row['imag']) as $url)` as I wrote in my answer – splash58 Jan 11 '19 at 10:09
  • omgggg i got itt i got answr thank youuuuu thank you so much –  Jan 11 '19 at 10:12
  • Since your images do not load properly i assume that they aren't implemented in the DB as an Blob. This should be helpful: https://stackoverflow.com/questions/20556773/php-display-image-blob-from-mysql – Drarula Jan 11 '19 at 10:00
  • but if im not using this ... using just simple inner join only i get image properly.. it display properly... –  Jan 11 '19 at 10:03
  • they are reading image names properly but while im displaying it on table it is not proper... butit is working well with all other innr join and queries –  Jan 11 '19 at 10:05
  • Can you show me what you get when you use inner join? Don't quite get what you mean. – Drarula Jan 11 '19 at 10:06
  • i think it iis reading the all image name as a single line and breaking it –  Jan 11 '19 at 10:08
  • Why dont you var_dump the query and see what you get as an output? – Drarula Jan 11 '19 at 10:16
  • i got the answer....splash58 helped.. im getting proper output now...... Thanks for the help:D –  Jan 11 '19 at 10:26

0 Answers0