IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

pagination d'un fichier xml


Sujet :

Langage PHP

  1. #1
    Membre régulier

    Profil pro
    Inscrit en
    Juin 2004
    Messages
    161
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 161
    Points : 97
    Points
    97
    Par défaut pagination d'un fichier xml
    Bonjour, j'ai quelque soucis je n'arrive pas à afficher une pagination de mon fichier xml comportant pres de 800 item.

    J'arrive pour l'instant à afficher les 10 premiers, mais comment faire pour afficher les autres via un lien par exemple : page 1 , page 2 ect ...

    voici mon code, la ou j'en suis pour l'instant.

    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    <?php
     
    // le répertoire "cache" 
     
    $dir_cache = 'cache/';
     
    // nom du fichier mis en cache
    $file_cache1 = 'flux1.html';
     
    if (!is_dir($dir_cache)) {
    exit ('Répertoire cache "'.$dir_cache.'" inexistant !');
    }
     
     
    // on impose la mise à jour avec une certaine periodicité
    $date_modif1 = time();
    // le delai entre deux rafraichissements en secondes 
    $delai1 = 43200;
     
     
    // le fichier est-il en cache et suffisamment jeune
    $file_cache1 = $dir_cache.$file_cache1;
    $en_cache1 = file_exists($file_cache1);
    if ($en_cache1) {
    $en_cache1 = ($date_modif1 < filemtime($file_cache1) + $delai1);
    }
     
    if (!$en_cache1) {
    // Lecture d'un fichier XML
    function lit_xml1($fichier,$item,$champs) 
    {
    // on lit le fichier
    	if($chaine = @implode("",@file($fichier))) 
    	{
    		// on explode sur <item>
    		$tmp = preg_split("/<\/?".$item.">/",$chaine);
     
     
    		$nombre = sizeof($tmp);
    		$items=40; // nombre d'items voulu
    		$limite=$debut+1+$items;
     
    		if($nombre<=$items)
    		{
    			$debut=0;
    			$limite=$nombre;
    		}
     
    		// pour chaque <item>
    		for($i=$debut+1;$i<$limite -1;$i+=2)         // on lit les champs demandés <champ>
    			foreach($champs as $champ) 
    			{
    				$tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);    // on ajoute au tableau
    				$tmp3[$i-1][] = @$tmp2[1];        
    			}     
    		// et on retourne le tableau
    		return $tmp3;  
    	}
    }
     
    // Exemple :
    $xml1 = lit_xml1("rss/liste_site/liste_site_18.xml","item",array("num","id_site","title","url","description","ins","outs","new_url","country","click_out_lien",));
     
    foreach($xml1 as $row1) { 
     
    	$row1[2] = str_replace('<![CDATA[', '', $row1[2]);
    	$row1[2] = str_replace(']]>', '', $row1[2]);
     
    	$row1[3] = str_replace('<![CDATA[', '', $row1[3]);
    	$row1[3] = str_replace(']]>', '', $row1[3]);
     
    	$row1[4] = str_replace('<![CDATA[', '', $row1[4]);
    	$row1[4] = str_replace(']]>', '', $row1[4]);
     
    	$row1[7] = str_replace('<![CDATA[', '', $row1[7]);
    	$row1[7] = str_replace(']]>', '', $row1[7]);
     
    	$row1[8] = str_replace('<![CDATA[', '', $row1[8]);
    	$row1[8] = str_replace(']]>', '', $row1[8]);
     
    	$row1[9] = str_replace('<![CDATA[', '', $row1[9]);
    	$row1[9] = str_replace(']]>', '', $row1[9]);
     
    	$data1 .= '<table width="607" border="0" align="center" cellpadding="0" cellspacing="0">
    				<tr>
    				<td width="15">&nbsp;</td>
    				<td>
    				<table width="100%" border="0" cellspacing="0" cellpadding="0">';
     
    	$data1 .=	'<tr><td height="20" valign="top" class="texte_arial-13-gras-rouge"><a href="'.$row1[3].'" onmousedown="return out(\''.$row1[9].'\')" " target="_blank" class="lien_arial-13-gras-rouge_souligne">'.$row1[2].'</a></td>
    				</tr>';
     
    	$data1 .=	'<tr>
    				<td><a href="'.$row1[3].'" onmousedown="return sponsor(\''.$row1[9].'\')" target="_blank" class="lien_arial-12-normal-noir_idem">'.$row1[4].'</a></td>
    				</tr>
    				<tr>
    				<td class="texte_arial-12-normal-noir" height="15" valign="bottom"><a href="'.$row1[3].'" onmousedown="return sponsor(\''.$row1[9].'\')" target="_blank" class="lien_arial-10-normal-gris-clair_souligne">Fiche du site : '.$row1[2].'</a></td>
    				</tr>
    				</table>
    				</td>
    				<td width="77" align="center"><img src="images/flag-france.gif" width="19" height="13" alt="france"></td>
    				<td width="77" align="center" class="texte_arial-11-normal-gris">'.$row1[5].'</td>
    				<td width="77" align="center" class="texte_arial-11-normal-gris">'.$row1[6].'</td>
    				</tr>
    				</table>
    				<table width="599" border="0" align="center" cellpadding="0" cellspacing="0">
    				<tr>
    				<td background="images/ico_pointilles_sites.gif"><img src="images/spacer.gif" width="100%" height="13" alt="'.$alt_page.'"></td>
    				</tr>
    				</table>';
     
    }
     
    $fd1 = fopen($file_cache1, "w");
    fputs($fd1, $data1);
    fclose($fd1);
     
    } // fin if !$en_cache1
     
    include $file_cache1;
    ?>
    merci de votre aide

  2. #2
    Membre éclairé Avatar de nako
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2003
    Messages
    577
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2003
    Messages : 577
    Points : 663
    Points
    663
    Par défaut
    Salut, je n'ai pas eu le courage de lire tout ton code, mais le principe, quand on veut faire de la pagination, c'est de donner en paramètre de ta page la position du premier item à afficher ($first_item par exemple), puis le nombre d'item à afficher ($nb_items par exemple).

    Pour la première page, ça donne :
    $first_item = 0; $nb_items = 10;
    le lien suivant sera donc : $first_item = 10 (first + nb); $nb_items = 10;
    le lien 2 sera donc : $first_item = 20 (first + 2*nb); $nb_items = 10;
    etc ...

    Voilà le principe.
    J'espère que ça répond à ta question.
    a+

Discussions similaires

  1. Recuperation du fichier xml
    Par Geulderack dans le forum XMLRAD
    Réponses: 10
    Dernier message: 28/02/2003, 11h06
  2. Insertion dans un fichier XML
    Par [DreaMs] dans le forum XMLRAD
    Réponses: 4
    Dernier message: 27/02/2003, 17h16
  3. Lire un attribut dans un fichier XML en C++
    Par ti.k-nar dans le forum XML
    Réponses: 2
    Dernier message: 14/10/2002, 15h22
  4. [Kylix] Composant IBM pour fichiers XML
    Par Mister Nono dans le forum EDI
    Réponses: 1
    Dernier message: 29/09/2002, 20h28
  5. Balises HTML dans un fichier XML
    Par Bastet79 dans le forum XML/XSL et SOAP
    Réponses: 12
    Dernier message: 04/09/2002, 15h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo