# Loop mysql query

**URL:** https://forum.kirupa.com/t/loop-mysql-query/249894
**Category:** Uncategorized
**Created:** [January 23, 2008, 2:56pm UTC](https://forum.kirupa.com/t/loop-mysql-query/249894 "2008-01-23T14:56:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![alapimba](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@alapimba](https://forum.kirupa.com/u/alapimba)
#### Post date: [January 23, 2008, 2:56pm UTC](https://forum.kirupa.com/t/loop-mysql-query/249894/1 "2008-01-23T14:56:53Z")

</div>

Hello  
I have 2 mysql tables. lets say One table has id and name, the other has id\_pic, foto, description and name\_id  
I have a query that join both tables and make a comparation so i can have the name and the fotos and descriptions. I did this because each person can have multiple fotos. So one table has name of the persons and the other has pictures.  
My query is: $query\_rs\_fotos = “SELECT \* FROM table 1, table 2 WHERE table 1.id = table 2.name\_id”;  
Now i want to have the result of this query looped but i don’t know how to loop it and separate the data.  
Lets say i have this data:  
:::.table 1:::::  
id | name  
1 | john  
2 | bob

::::table 2:::::  
id\_pic | foto | description | name\_id  
1 | bla.jpg | bla | 1  
2 | buh.jpg | buh | 2  
3 | yah.jpg | yah | 1  
4 | boing.jpg | boing | 1  
5 | bang.jpg | bang | 2  
i want the loop to return something like:  
\<table\>  
\<tr\>\<td\> john\</td\>\</tr\>  
\<tr\>\<td\> bla.jpg\</td\>\<td\> yah.jpg\</td\>\</tr\>  
\<tr\>\<td\> boing.jpg\</td\>\</tr\>  
\<tr\>\<td\> bob\</td\>\</tr\>  
\<tr\>\<td\> buh.jpg\</td\>\<td\> bang.jpg\</td\>\</tr\>  
\</table\>  
How can i do this? ???
