PhpHtmlDeveloperEXPERT PhpHtmlDeveloperEXPERT - 4 months ago 11
PHP Question

anyone know why I keep getting duplicate images

Its suppose to be a gallery that displays images from two joined tables. Somehow two duplicate images instead of one keeps popping up. It only happens when I joined the tables. Is there a way to prevent this using javascript or some php code. I'm I doing something wrong.

Answer

change your query to this.

     $sql = "  SELECT images.id, header.username, images.message, images.name
   FROM images
   INNER JOIN header
   ON images.message=header.file 
   group by images.id; ";
  • you missed to GROUP BY image id to dont get dublicates