Précédent   Forum des professionnels en informatique > PHP > Langage > Syntaxe
Syntaxe Forum d'entraide sur la syntaxe de PHP et la POO. Avant de poster -> FAQ syntaxe, Cours d'initiation et cours de POO
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 11/01/2012, 22h27   #1
Futur Membre du Club
 
Inscription : novembre 2007
Messages : 148
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 148
Points : 18
Points : 18
Par défaut Flux XML qui n'affiche rien

Bonsoir à tous,

Je tente d'utiliser le flux XML ci-dessous... mais je dois mal m'y prendre car il devrait afficher des bannières les unes après les autres, mais RIEN ne s'affiche, ni bannière ni erreur. Où me suis je trompé ??

MERCI BEAUCOUP,
Antoine

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<? 
 
$ip = $_SERVER['REMOTE_ADDR'] ;
$url = 'http://www.adincent.com/xml/xml.php?id=6027&ip='.$ip ;
$xml = simplexml_load_file($url) ;
 
foreach($xml->result as $obj)
{
 
	echo '<a href=""'.$obj->link.'" 
onclick="window.open(\'validation.php?c1=\'+document.getElementById(\'c1\').value+\'&c2=\'+document.getElementById(\'c2\').value+\'&c3=\'+document.getElementById(\'c3\').value+\'&c4=\'+document.getElementById(\'c4\').value+\'&c5=\'+document.getElementById(\'c5\').value+\'&c6=\'+document.getElementById(\'c6\').value,\'validation\',\'toolbar=0,menubar=0,location=0,scrollbars=1,width=400,height=300\')"><img 
src=""'.$obj->banner.'"></a><br><br>';
 
}
 
 ?>
ingeniomatique est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h33   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
faut faire une requête xpath (//result) le XML est pas très bien fait malheuresement
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h36   #3
Futur Membre du Club
 
Inscription : novembre 2007
Messages : 148
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 148
Points : 18
Points : 18
Je ne maîtrise malheureusement pas trop ça... Ca fonctionne comment ce type de requêtes ?? Merci par avance de votre aide, c'est gentil
ingeniomatique est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h37   #4
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
juste ça devrait aller :

Code :
foreach($xml->xpath('//result') as $obj)
http://www.php.net/manual/fr/simplexmlelement.xpath.php
http://fr.wikipedia.org/wiki/XPath
http://www.w3.org/TR/xpath/
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h48   #5
Futur Membre du Club
 
Inscription : novembre 2007
Messages : 148
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 148
Points : 18
Points : 18
Je viens donc de tester... ça n'affiche RIEN non plus...
ingeniomatique est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h49   #6
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
Citation:
Envoyé par ingeniomatique Voir le message
Je viens donc de tester... ça n'affiche RIEN non plus...
si tu fais un var_dump($obj); dans la boucle ça donne quoi ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h51   #7
Futur Membre du Club
 
Inscription : novembre 2007
Messages : 148
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 148
Points : 18
Points : 18
Ca donne ça :

Code :
1
2
3
object(SimpleXMLElement)#6 (3) { ["banner"]=> string(64) "http://www.kadoweb.net/bannieres/creditneto_generique_468x60.gif" ["link"]=> string(67) "http://www.adincent.com/ads/annonceur.php?uid=6027&adv=100&message=" ["adult"]=> string(1) "0" } 
 
object(SimpleXMLElement)#5 (3) { ["banner"]=> string(64) "http://www.kadoweb.net/bannieres/creditneto_generique_468x60.gif" ["link"]=> string(67) "http://www.adincent.com/ads/annonceur.php?uid=6027&adv=100&message=" ["adult"]=> string(1) "0" }
Affiché en texte
ingeniomatique est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 22h56   #8
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
en faisant

Code :
1
2
3
4
5
$xml = simplexml_load_file($url) ;
 
foreach ($xml->result as $obj) {
    printf('<a href="%s"><img src="%s" alt="banner"/></a>', $obj->link, $obj->banner);
}
ça marche, dans le code source j'ai le code, par contre il n'affiche rien, étrange
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 23h16   #9
Futur Membre du Club
 
Inscription : novembre 2007
Messages : 148
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 148
Points : 18
Points : 18
D'où mon post... Je ne comprends pas trop...
Je vais creuser ! Merci de l'aide
ingeniomatique est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h06.


 
 
 
 
Partenaires

Hébergement Web