Précédent   Forum des professionnels en informatique > PHP > Langage > Fonctions
Fonctions Forum d'entraide sur les fonctions PHP. Avant de poster -> FAQ fonctions et Sources diverses
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 14/12/2011, 18h42   #1
Membre du Club
 
Inscription : janvier 2007
Messages : 236
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 236
Points : 62
Points : 62
Par défaut Fil d'ariane à partir d'un résultat de requête nested

salut à tous

j'ai un objet du genre (résultat de requête)
Code :
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
 
0 => 
    array
      'idPage' => string '8' (length=1)
      'titrePage' => string 'Accueil' (length=7)
      'nomLien' => string 'Accueil' (length=7)
      'urlSeoPage' => string 'Accueil' (length=7)
      'depth' => string '1' (length=1)
      'parent' => string '0' (length=1)
      'text' => string '<a href="http://demo.local">Accueil</a>' (length=54)
  1 => 
    array
      'idPage' => string '9' (length=1)
      'titrePage' => string 'Société' (length=9)
      'nomLien' => string 'Société' (length=9)
      'urlSeoPage' => string 'Societe' (length=7)
      'depth' => string '2' (length=1)
      'parent' => string '8' (length=1)
      'text' => string '<a href="http://demo.local/9-Societe">Société</a>' (length=56)
  2 => 
    array
      'idPage' => string '11' (length=2)
      'titrePage' => string 'Activités' (length=10)
      'nomLien' => string 'Activités' (length=10)
      'urlSeoPage' => string 'Activites' (length=9)
      'depth' => string '3' (length=1)
      'parent' => string '9' (length=1)
      'text' => string '<a href="http://demo.local/11-Activites">Activités</a>' (length=60)
  3 => 
    array
      'idPage' => string '20' (length=2)
      'titrePage' => string 'Partenaires' (length=11)
      'nomLien' => string 'Partenaires' (length=11)
      'urlSeoPage' => string 'Partenaires' (length=11)
      'depth' => string '1' (length=1)
      'parent' => string '0' (length=1)
      'text' => string '<a href="http://demo.local/20-Partenaires">Partenaires</a>' (length=63)
  4 => 
    array
      'idPage' => string '21' (length=2)
      'titrePage' => string 'COntact' (length=7)
      'nomLien' => string 'Contact' (length=7)
      'urlSeoPage' => string 'COntact' (length=7)
      'depth' => string '2' (length=1)
      'parent' => string '20' (length=2)
      'text' => string '<a href="http://demo.local/21-COntact">Contact</a>' (length=55)
qui traduit l'arborescence suivante

Accueil |
--- Société |
------ Activités |

Partenaires |
--- Contact

j'aimerai faire une fonction dans laquelle je dise
crée moi le fil d'arianne de la page activités

et la fonction me renvoi accueil > societe > activites

vous voyez le délire ?
ben en fait c'est achement compliqué :'(
il faut partir en sens inverse ... et remonter l'arbre pour ne garder que ce qui m'intéresse...
du coup je sais pas trop

vala vala ..
si qqun à ça sous la main

thanks !
@+
CaviarNAS est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2011, 19h00   #2
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Créer un "chemin de fer" (suite de lien donnant la position dans l'arborescence d'un site)

ceci pourrait aussi t’être utile Générer un plan d'un site sous forme de listes imbriquées
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2011, 19h03   #3
Membre du Club
 
Inscription : janvier 2007
Messages : 236
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 236
Points : 62
Points : 62
yes, mais l'idée est de ne pas refaire appel à des requêtes
j'ai tout ce qu'il faut dans mon objet ...
j'aimerai l'utiliser et me servir des propriétés parent ...

j'ai fait ça mais ça tourne en boucle ...

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function ariane($idPage) {
 
 
			foreach($this->tree as $k=>$node){
				trace ($node, $idPage);
				if (trim($node['idPage']) == trim($idPage)) {
					$result .= '>'.$node['nomLien'] ;
					$parent = $node['parent'] ;
 
				}
 
			}
 
			while ($parent != 0) {
				$result .= $this->ariane ($parent);
			}
			trace ($result, 'result')	;
		return $result;	
 
	}
CaviarNAS est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2011, 19h18   #4
Membre du Club
 
Inscription : janvier 2007
Messages : 236
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 236
Points : 62
Points : 62
bon j'ai trouvé ...
c'est un peu freestyle mais bon

Code :
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
	function getParent($idPage) {
		foreach($this->tree as $k=>$node){
			if (trim($node['idPage']) == trim($idPage)) {
				$this->ariane[] = $node ;
				return $node['parent'] ;
			}
		}
	}
 
	function ariane($idPage) {	
 
			foreach($this->tree as $k=>$node){
			//	trace ($node, $idPage);
				if (trim($node['idPage']) == trim($idPage)) {
					$this->ariane[] =  $node ;
					$parent = $node['parent'] ;					
				}			
			}
 
			while ($parent != 0) {
				$parent = $this->getParent ($parent);
			}
 
			//trace ($result, 'result')	;
 
			 asort($this->ariane);
			//trace ($this->ariane, 'ariane')	;
 
			foreach ($this->ariane as $a) {
				$r .= $a['text'];
				if ($i+1 < count($this->ariane) ) {
					$r .= $this->arianeDelimiter;
				}
				$i++;
			}
			return $r;	
 
	}
si ça peut aider
++
CaviarNAS est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h59.


 
 
 
 
Partenaires

Hébergement Web