Code basique de Php pour une navigation dynamique

Eléphant du PHP | 184 Messages

12 sept. 2006, 22:08

Je ne vois pas ce que vient faire la 1ere partie dans la page, tu fais la même chose avec des tests en plus sur la seconde. Pour ton erreur tu n'as pas mis le cas lorsque page=rien.


Edit : un chouilla en retard sur charabia, ca fait un peu doublon
Image

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:23

Ok j'ai supprimé le code:
<?php 
include($_GET['page'].'.php'); // Nous appelons le contenu central de la page 
?> 
Il ne me reste plus que celui-ci placé dans mon cadre:
<?php

  // On définit le tableau contenant les pages autorisées
  // ----------------------------------------------------
  $pageOK = array('echecs' => 'echecs.php',
                  'accueil' => 'accueil.php');

  // On teste que le paramètre d'url existe et qu'il est bien autorisé
  // -----------------------------------------------------------------
  if ( (isset($_GET['page'])) && (isset($pageOK[$_GET['page']])) ) {
    include($pageOK[$_GET['page']]);   // Nous appelons le contenu central de la page
  } else {
    include('accueil.php');   // Page par défaut quant elle n'existe pas dans le tableau
  }

?>
A l'arrivée sur le site j'ai bien ma page accueil.php qui se greffe dans le cadre. En revanche, en cliquant sur le lien Echecs, j'atterris toujours sur la page accueil.php.
Sur le lien echecs dans le menu j'ai mis ceci:

Code : Tout sélectionner

<a href="index.php?page=echecs">Echecs</a>
Qu'ais-je fait de mal ? :p

ps: désolé de vous embêter avec ça ^^

Avatar du membre
ViPHP
ViPHP | 3008 Messages

12 sept. 2006, 22:30

ça devrait fonctionner pourtant...tu peux nous afficher ton code complet ? Là dans ce que tu nous donnes je ne vois pas le souci...

Ta page echecs.php est bien différente de accueil.php...?

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:32

Voici donc le code complet de ma page index.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>KELBOREVE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE type=text/css>A {
	FONT-WEIGHT: bold; COLOR: #000000; TEXT-DECORATION: none
}
A:hover {
	FONT-WEIGHT: bold;
	TEXT-DECORATION: underline;
	COLOR: #FF0000;
}
TD {
	FONT-SIZE: 10pt; FONT-FAMILY: Verdana,Geneva,Arial,Helvetica,sans-serif
}
TD.titre {
	FONT-SIZE: 7.5pt; FONT-FAMILY: Verdana,Geneva,Arial,Helvetica,sans-serif; FONT-WEIGHT: bold;
}
</STYLE>

</head>

<body bgcolor="#57B6FB">
<div align="center">
  <table width="1024" border="0" cellpadding="0" cellspacing="1">
    <tr> 
      <td width="800"> 
        <table width="700" border="0" cellpadding="0" cellspacing="0">
          <tr> 
            <td width="860"> 
              <p align="center"><br>
                <img src="images/bandeau%20copie.jpg" width="764" height="116"></p>
              <p align="center"><br>
              </p>
              <div align="center"> 
                <table width="935" border="0" cellspacing="0" cellpadding="0">
                  <tr valign="top"> 
                    <td width="184" height="511" align="center"> <table width="160" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                        <tr> 
                          <td><table width="160" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                              <tr> 
                                <td height="17" align="center" background="images/haut.jpg" class="titre">Nos 
                                  Sorties </td>
                              </tr>
                              <tr> 
                                <td align="center"><table width="160" border="0" cellspacing="4" cellpadding="0" bgcolor="#FFFFFF">
                                    <tr> 
                                      <td align="center"><p><font size="1"><a href="#">Parc 
                                          d'attractions </a><br>
                                          <a href="#">Parcs naturels</a><br>
                                          <a href="#">Parc aquatiques</a><br>
                                          <a href="#">Villes</a><br>
                                          <a href="#">Zones de loisirs</a></font></p></td>
                                    </tr>
                                  </table></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <br>
                      <table width="160" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                        <tr> 
                          <td><table width="160" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                              <tr> 
                                <td height="17" align="center" background="images/haut.jpg" class="titre">Coin 
                                  gourmand </td>
                              </tr>
                              <tr> 
                                <td align="center"><table width="160" border="0" cellspacing="4" cellpadding="0" bgcolor="#FFFFFF">
                                    <tr> 
                                      <td align="center"><font size="1"><a href="#">Restaurants</a><br>
                                        <a href="#">Recettes</a></font></td>
                                    </tr>
                                  </table></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <br>
                      <table width="160" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                        <tr> 
                          <td><table width="160" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                              <tr> 
                                <td height="17" align="center" background="images/haut.jpg" class="titre">H&eacute;bergement</td>
                              </tr>
                              <tr> 
                                <td align="center"><table width="160" border="0" cellspacing="4" cellpadding="0" bgcolor="#FFFFFF">
                                    <tr> 
                                      <td height="24" align="center"><font size="1"><a href="#">Hôtels</a><br>
                                        <a href="#">G&icirc;tes</a></font></td>
                                    </tr>
                                  </table></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <br>
                      <table width="160" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                        <tr> 
                          <td><table width="160" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                              <tr> 
                                <td height="17" align="center" background="images/haut.jpg" class="titre">Nos 
                                  Loisirs </td>
                              </tr>
                              <tr> 
                                <td align="center"><table width="160" border="0" cellspacing="4" cellpadding="0" bgcolor="#FFFFFF">
                                    <tr> 
                                      <td height="24" align="center"><font size="1"> 
                                        <a href="index.php?page=echecs">Echecs</a><br>
                                        <a href="index.php?page=tarot" "Tarot ">Tarot</a><br>
                                        <a href="#">Champignons</a><br>
                                        <a href="#">Tricot</a><br>
                                        <a href="#">Dessin</a><br>
                                        <a href="#">Pêche</a><br>
                                        <a href="#">Lecture</a><br>
                                        <a href="#">Cinéma</a><br>
                                        <a href="#">Tv</a></font></tr>
                                  </table></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <br>
                      <table width="160" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                        <tr> 
                          <td><table width="160" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                              <tr> 
                                <td height="17" align="center" background="images/haut.jpg" class="titre">Dijon</td>
                              </tr>
                              <tr> 
                                <td align="center"><table width="160" border="0" cellspacing="4" cellpadding="0" bgcolor="#FFFFFF">
                                    <tr> 
                                      <td height="24" align="center"><p><font size="1"> 
                                          <a href="#">Parcs</a><br>
                                          <a href="#">Ballades</a><br>
                                          <a href="#">Restautants</a><br>
                                          <a href="#">Evènements</a><br>
                                          </font></p></td>
                                    </tr>
                                  </table></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table>
                      <br> <br> </td>
                    <td width="751" align="center"> <div align="center"> 
                        <table width="550" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
                          <tr> 
                            <td><table width="550" height="75" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                                <tr> 
                                  <td width="550" height="17" align="center" background="images/haut.jpg" class="titre">&nbsp;</td>
                                </tr>
                                <tr> 
                                  <td><table width="579" border="0" cellspacing="5" cellpadding="4" bgcolor="#FFFFFF">
                                      <tr> 
                                        <td width="561"><p> 
                                            <?php

  // On définit le tableau contenant les pages autorisées
  // ----------------------------------------------------
  $pageOK = array('echecs' => 'echecs.php',
                  'accueil' => 'accueil.php');

  // On teste que le paramètre d'url existe et qu'il est bien autorisé
  // -----------------------------------------------------------------
  if ( (isset($_GET['page'])) && (isset($pageOK[$_GET['page']])) ) {
    include($pageOK[$_GET['page']]);   // Nous appelons le contenu central de la page
  } else {
    include('accueil.php');   // Page par défaut quant elle n'existe pas dans le tableau
  }

?>
                                          </p>
                                          <p>&nbsp; </p>
                                          
										  <p>&nbsp;</p>
                                          </td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></td>
                          </tr>
                        </table>
                      </div></td>
                  </tr>
                </table>
              </div></td>
          </tr>
          <tr> 
            <td height="25" align="center" valign="middle"></td>
          </tr>
          <tr> 
            <td height="17" align="center" valign="middle" background="images/head3.jpg"><font color="#808080">Copyright 
              © 2006 - </font><b>Kelboreve</b><font color="#808080"> - Tous droits 
              réservés</font></td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</div>
</body>
</html>

Avatar du membre
ViPHP
ViPHP | 3008 Messages

12 sept. 2006, 22:35

Tout fonctionne. C'est bête mais...as-tu vérifié que ta page accueil et echecs sont différentes ? lol

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:41

Oui elle sont bien différentes :)

Voici leur code:

Accueil=>

Code : Tout sélectionner

<html> <head> <title>Document sans titre</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p>Bienvenu sur mon site </p> </body> </html>
Echecs=>

Code : Tout sélectionner

<html> <head> <title>Les echecs</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> On joue aux échecs...</html>

Avatar du membre
ViPHP
ViPHP | 3008 Messages

12 sept. 2006, 22:43

Tes pages incluses ne doivent pas avoir le début et la fin du code HTML sinon ça fait doublon.

Donc tu ne dois avoir que le contenu,

Code : Tout sélectionner

<p>Bienvenu sur mon site </p> et On joue aux échecs...
Tout le reste est à virer.

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:48

Je dois être maudit ^^

j'ai une seule ligne de code dans la page echecs=>

Code : Tout sélectionner

<p>Bienvenu sur mon site </p>
Et elle s'affiche toujours pas :(

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:49

pardon

Code : Tout sélectionner

<p>On joue aux échecs</p>
C'est bien ca qu'il y a :p[/code]

Avatar du membre
ViPHP
ViPHP | 3008 Messages

12 sept. 2006, 22:51

Pour ton lien tarot il est bizarre :

Code : Tout sélectionner

<a href="include.php?page=tarot" "Tarot ">
Ton code marche chez moi. Pour isoler le problème, prend mon code tout simple que j'ai donné en exemple pour voir si ça fonctionne.

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:54

oui je 'ai refait, maintenant c'est:

Code : Tout sélectionner

<a href="index.php?page=tarot">Tarot</a>
J'arrête pour ce soir, je verrai demain soir, merci du coup de main, en espérant que toi ou quelqu'un d'autre voit qu'est-ce qui va pas car là c'est bizarre.

Merci d'avance

Eléphanteau du PHP | 18 Messages

12 sept. 2006, 22:57

Ca ne fonctionne pas non plus avec le code:
<?php  

$pageOK = array('echecs' => 'echecs.php',  
'accueil' => 'accueil.php');  


if ( (isset($_GET['page'])) && (isset($pageOK[$_GET['page']])) ) {  
include($pageOK[$_GET['page']]);  
} else {  
include('accueil.php'); }  

?>

Eléphant du PHP | 184 Messages

12 sept. 2006, 23:02

rajoute voir cette ligne avant ton include :
echo "page : ".$_GET['page']." include : ".$pageOK[$_GET['page'];
Image

Eléphanteau du PHP | 18 Messages

13 sept. 2006, 00:02

Ca donne ce code
<?php

  // On définit le tableau contenant les pages autorisées
  // ----------------------------------------------------
  $pageOK = array('echecs' => 'echecs.php',
                  'accueil' => 'accueil.php');

  // On teste que le paramètre d'url existe et qu'il est bien autorisé
  // -----------------------------------------------------------------
  if ( (isset($_GET['page'])) && (isset($pageOK[$_GET['page']])) ) {
 echo "page : ".$_GET['page']." include : ".$pageOK[$_GET['page']];  
	include($pageOK[$_GET['page']]);   // Nous appelons le contenu central de la page
  } else {
    include('accueil.php');   // Page par défaut quant elle n'existe pas dans le tableau
  }

?>

Mais le résultat est le même :-(

Eléphant du PHP | 184 Messages

13 sept. 2006, 00:05

La ligne ne changera rien au résultat escompté mais elle te permet de voir l'état des variables, ca s'appelle du débogage :)

Donne nous les infos affichées grâce à cette ligne.

Edit : place la ligne avant le if()
Image