$query = mysql_query("SELECT * FROM table1, table2, table3, table4
WHERE table1.CatID = table2.CatID
AND table1.DogID = table3.DogID
AND table1.PigID = table4.PigID
AND table1.tblStatus =1 ORDER BY ID DESC ");
while ($row = mysql_fetch_assoc($query)) {
$query_image = mysql_query("SELECT table5.tblPhotos, table5.ID,table1.ID
FROM table5,table1
WHERE table5.ID = table1.ID
AND table1.ID =".$row["ID"]); // ID ที่อ้างอิง
$row_image = mysql_fetch_assoc($query_image);
..................................................................
}