How to bring the result of the clustered MYSQL query and make a foreach for each group

0

I have a real estate site that assembles a photo album for each type of photos: Facade, Common Area, Floor and Decor.

To do this, I do 4 MYSQL queries with PHP, using the criteria for each, but I believe that I should have a one-time solution.

Below I do currently (I put only facade and floor, but I repeat the code for common area and decorated too):

$id = $_POST['idlancamento'];
echo'
<div id="fachada">
<ul>';
$db -> setQuery("SELECT * FROM #__lancamentos_fotos WHERE idlancamento = '".$id."' AND tipo = 'Fachada'");
$fotos = $db->loadObjectList();
foreach($fotos as $f){
    echo '
    <li><img src="/images/lancamentos/'.$id.'/'.$f->fotos.'"></li>
    ';
}
echo'</ul></div>';

echo'
<div id="planta">
<ul>';
$db -> setQuery("SELECT * FROM #__lancamentos_fotos WHERE idlancamento = '".$id."' AND tipo = 'Planta'");
$fotos = $db->loadObjectList();
foreach($fotos as $f){
    echo '
    <li><img src="/images/lancamentos/'.$id.'/'.$f->fotos.'"></li>
    ';
}
echo'</ul></div>';


a tabela #__lancamentos_fotos é assim:
id|idlancamento|tipo      |fotos
1 | 9          |Fachada   |foto1.jpg
2 | 9          |Planta    |fotoa.jpg
3 | 9          |Fachada   |foto2.jpg
4 | 9          |Área Comum|foto9.jpg
5 | 9          |Decorado  |foto8.jpg

I believe there should be a way to just make a query and simplify this code, can anyone help me?

    
asked by anonymous 06.08.2018 / 15:37

0 answers