Skip to content
Advertisement

Foreach loop but print one time with multiple value

So I have in my database a table called "Clients" and an other one called "Pets". They are linked by an associative table which means that a "Clients" can have two "Pets".

I am using a FOREACH loop to display my client and pets but when a client have many pets, my foreach loop print everything, as many as the client have pets.

see here

here is my foreach loop

JavaScript

My problem is that I want to have everything diplayed normally except the "pets" (<?= $file['petName']; ?>) and see that the client have 2 pets..

like this :

Thanks for your help !

My SQL query

JavaScript

Advertisement

Answer

You can change query like:

JavaScript

It’s not solution, but can can give you an idea for best solution.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement