Bonjour, j'essaye de trier après un fetchAll(); j'ai réussi a faire ce que je voulais mais je ne sais pas si je peux faire plus simple.

voici 2 tulpes de bas base de donnée je les obtiens avec ce script sur le controleur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
        $sql=$table_car->fetchAll();
        $this->view->voitures=$sql->toArray();
sur la vue voici ce que ça donne avec un var_dump($this->voiture)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
array
  0 => 
    array
      'id' => string '1' (length=1)
      'nom' => string '106' (length=3)
      'prix' => string '15000' (length=5)
      'year' => string '2011' (length=4)
      'km' => string '23005' (length=5)
      'couleur' => string 'blue' (length=4)
      'meca' => string 'semi-automatique' (length=16)
      'nb_meca' => string '5' (length=1)
      'energie' => string 'solaire' (length=7)
      'fisco' => string '100' (length=3)
      'caros' => string 'berline' (length=7)
      'decrit' => string 'voiture ancienne' (length=16)
      'foto_show' => string 's1' (length=2)
      'mini1' => string 'm1' (length=2)
      'mini2' => string 'm2' (length=2)
      'mini3' => string 'm3' (length=2)
      'mini4' => string 'm4' (length=2)
      'big1' => string 'b1' (length=2)
      'big2' => string 'b2' (length=2)
      'big3' => string 'b3' (length=2)
      'big4' => string 'b4' (length=2)
  1 => 
    array
      'id' => string '2' (length=1)
      'nom' => string 'sariz' (length=5)
      'prix' => string '99000' (length=5)
      'year' => string '3000' (length=4)
      'km' => string '12201111' (length=8)
      'couleur' => string 'metal ' (length=6)
      'meca' => string 'atiomique' (length=9)
      'nb_meca' => string '5' (length=1)
      'energie' => string 'solaire' (length=7)
      'fisco' => string '0' (length=1)
      'caros' => string 'camion' (length=6)
      'decrit' => string 'derni�re technologique' (length=22)
      'foto_show' => string 's2' (length=2)
      'mini1' => string 'm5' (length=2)
      'mini2' => string 'm6' (length=2)
      'mini3' => string 'm7' (length=2)
      'mini4' => string 'm8' (length=2)
      'big1' => string 'b5' (length=2)
      'big2' => string 'b6' (length=2)
      'big3' => string 'b7' (length=2)
      'big4' => string 'b8' (length=2)
mon but:

d'afficher tous ce qu'il y a dans le premier tulpe 0,
c'est une annonce de voiture par exemple, je mes des donnée sur le voiture en question et ensuite les photo, une fois le tuple fini, je passe a la suivante , ansi de suite, le poblème de fetchAll(), c'est que les données sont rangé par colonne et moi je veux par ligne

j'ai donc décider de filter toute les image, toute les information dans un tableau selon sont type, si c'est une image elle ira dans $image[] si c'est une info dans $info[] etc ..

voici ma vu qui trie les informations

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
//var_dump($this->voitures);
foreach($this->voitures as $tulpe)
{
 
    foreach($tulpe as $key=>$resultat)
    {
        if(preg_match("#[^mini|^big|^show]#",$key))
        {
            $info[] = $resultat;
        }
        if(preg_match("#mini#",$key))
        {
           $image[]=$resultat;
        }
 
        if(preg_match("#big#",$key))
        {
            $imagebig[]=$resultat;
        }
 
        if(preg_match("#show#",$key))
        {
                 $imagefirst=$resulat;
        }
 
 
    }
}
 
var_dump($mini);
?>
avant de commencer plus loin je souhaite savoir si je peux faire plus simple ??

je ne sais pas si j'ai bien formulé ma question?

je vous remercie de vos suggestions