Probleme php
Résolu
n1c065000
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
Lefouerrant Messages postés 567 Date d'inscription Statut Membre Dernière intervention -
Lefouerrant Messages postés 567 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je veux faire un script de news en php5 avec xml.
Voici mon code pour afficher les 2 dernières news:
<?php
if(!isset($_GET['news']))
$_GET['news']=0;
$xml = simplexml_load_file('news.xml');
$actu = $xml->item;
for ($i = $_GET['news']; $i <= ($_GET['news']+2); $i++)
echo '
<h1>'.$actu[$i]->title.'</h1>
<p>'.$actu[$i]->body.'</p>';
echo '<a href=for_tab.php?news='.($_GET['news']+2).'>plus</a>'; //pour afficher news anterieur
?>
avec news.xml du type:
<?xml version="1.0" encoding="utf-8"?>
<news>
<item>
<title>Bienvenue</title>
<body>Contenu 1</body>
</item>
<item>
<title>hdfhghgf</title>
<body>gfhg</body>
</item>
<item>
<title>ghgf</title>
<body>retr</body>
</item>
</news>
Voici l'erreur:
<b>Notice</b>: Trying to get property of non-object in <b>C:\Program Files\EasyPHP 3.0\www\php\for\for_tab.php</b> on line <b>11</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>C:\Program Files\EasyPHP 3.0\www\php\for\for_tab.php</b> on line <b>12</b><br />
Pourquoi?
merci de votre aide
Je veux faire un script de news en php5 avec xml.
Voici mon code pour afficher les 2 dernières news:
<?php
if(!isset($_GET['news']))
$_GET['news']=0;
$xml = simplexml_load_file('news.xml');
$actu = $xml->item;
for ($i = $_GET['news']; $i <= ($_GET['news']+2); $i++)
echo '
<h1>'.$actu[$i]->title.'</h1>
<p>'.$actu[$i]->body.'</p>';
echo '<a href=for_tab.php?news='.($_GET['news']+2).'>plus</a>'; //pour afficher news anterieur
?>
avec news.xml du type:
<?xml version="1.0" encoding="utf-8"?>
<news>
<item>
<title>Bienvenue</title>
<body>Contenu 1</body>
</item>
<item>
<title>hdfhghgf</title>
<body>gfhg</body>
</item>
<item>
<title>ghgf</title>
<body>retr</body>
</item>
</news>
Voici l'erreur:
<b>Notice</b>: Trying to get property of non-object in <b>C:\Program Files\EasyPHP 3.0\www\php\for\for_tab.php</b> on line <b>11</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>C:\Program Files\EasyPHP 3.0\www\php\for\for_tab.php</b> on line <b>12</b><br />
Pourquoi?
merci de votre aide
A voir également:
- Probleme php
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Retour a la ligne php - Forum Webmastering
- Alert php - Forum PHP
- Retour a la ligne php ✓ - Forum PHP
3 réponses
à la place de :
met :
je precise que je suis un novice dans la gestion du xml en php et donc que je ne suis pas sur de ma reponse
$actu = $xml->item;
met :
$actu=getElementsByTagName("item");
je precise que je suis un novice dans la gestion du xml en php et donc que je ne suis pas sur de ma reponse