Boucle while et for buguée

Fermé
Takumi - 12 juil. 2012 à 11:45
 Takumi - 13 juil. 2012 à 15:27
Bonjour,

Je suis sur la création d'un site en div avec javascript pour n'effectuer aucuns ou très peu de rechargement de pages. Très gourmand en ressource oui, mais c'est ce qui m'a été demandé.
Bref je fonctionne avec une page index.php qui inclus toutes mes autres page dans des divs qui sont en display=none. L'une de ces pages est la suivante :

Instrument.php
<style type="text/css" media="screen">
.tdcontenu {
border-style:solid;
border:thick double #000000;
}

.menu {
line-height:27px;
list-style:none;
border-style:solid;
border-left:thick double #000000;
border-top:none;
border-right:none;
border-bottom:none;
}

.menu li a {
color:#000;
font-size:.8em;
font-family:arial, verdana, sans-serif;
text-align:center;
text-decoration:none;
line-height:27px;
display:block;
float:left;
cursor:pointer
}

.menu li a span {
float:left;
display:block;
padding:0 14px 0 7px
}

.menu li a:hover {
color:#fff;
background:url(Design/onglet.png) no-repeat right top;;
}
</style>

<script type="text/javascript">
var OldTarget = document.getElementById('Intro');

function showInstru(instruID){
if (OldTarget != null) {
   var Old = document.getElementById(OldTarget);
   Old.style.display='none';
}
var Intro = document.getElementById('Intro');
Intro.style.display='none';
targetElement = document.getElementById(instruID);
OldTarget = targetElement.id;
targetElement.style.display='block';
}
</script>


<!-- Espace réserver au menu -->
<table width=100%><tr><td width=265px>
<ul class="menu">
<?
$Instru=mysql_query("SELECT * FROM Categorie WHERE ParentID = 1 ORDER BY Categorie");
while ($rowInstru=mysql_fetch_array($Instru)) {
?>
 <li><a href="javascript:showInstru('<? echo $rowInstru['Categorie']; ?>');"><span><? echo $rowInstru['Categorie'] ?></span></a></li><br>
<?
}
?>
</ul>
</td><td class="tdcontenu" align=center>
<DIV id="ARTICLE">
<?
$Instru=mysql_query("SELECT * FROM Categorie WHERE ParentID = 1");
while ($rowInstru=mysql_fetch_array($Instru)) {
echo '<DIV id="'.$rowInstru['Categorie'].'" style="Display:none;">';
 	
		$PageProd = 1;
		$messagesParPage=5;
		
		$retour_total=mysql_query('SELECT COUNT(*) AS total FROM Produit WHERE CategorieID = "'.$rowInstru['CategorieID'].'"');
		$donnees_total=mysql_fetch_assoc($retour_total);
		$total=$donnees_total['total'];
		
		$nombreDePages=ceil($total/$messagesParPage);
 		for($PageProd=1;$PageProd<=$nombreDePages;$PageProd++) {
 		$pageActuel = ($PageProd-1)*$messagesParPage;

 		
	 	$Article=mysql_query('SELECT * FROM Produit WHERE CategorieID = "'.$rowInstru['CategorieID'].'" ORDER BY "'.$rowInstru['Produit'].'" LIMIT '.$pageActuel.', '.$messagesParPage.'');
	 	
	 	echo "<DIV id=".$PageProd.">";
		while ($rowArticle=mysql_fetch_array($Article)) {
			
			$PicArt = mysql_fetch_array(mysql_query('SELECT * FROM ProduitPhoto WHERE ProduitID = "'.$rowArticle['ProduitID'].'"'));
			$Pic = substr($PicArt['File'],1,strlen($PicArt['File']));
			
			$Art = iconv("latin1", "UTF-8//TRANSLIT", $rowArticle['Produit']);
	 		echo '<Div align=left style="color:#FFF;border-radius: 10px;border-width:1px;border-style:solid;border-color:#000000;width:90%;background-image:url(Design/Opac.png);">';
	 		echo "<table style='color:#FFF;width:100%;'><tr><td rowspan=3 width=80><img src=".$Pic." width=80 height=80 style='border-radius: 10px;border-width:1px;border-style:solid;border-color:#000000;'></td><td align=left style='font-size:25;'>".$Art."</td></tr>";
	 		echo "<tr><td align=left style='font-style:italic;'>".$rowArticle['RefStock']."</td></tr><tr><td align=right style='font-size:25;font-weight:bold;'>".$rowArticle['PrixTTC']." Chf</td></tr></table></div><br>";
 		}
 		echo "</DIV>";
 		echo $PageProd;
 		}
 echo "</DIV>";
}
?>
<DIV id="Intro">
Séléctionnez une catégorie d'instruments
</DIV>
</DIV>
</td></tr></table>


Mon problème est très simple : Le bout de code ci dessous ne fonctionne pas. Après avoir retiré des bout de code pour voir ou sa merdouillais, j'ai pu constater qu'il n'y a que ma boucle for qui fait tout planter. (j'ai essayer de la remplacer par une while, même chose !!).

for($PageProd=1;$PageProd<=$nombreDePages;$PageProd++) {
 		$pageActuel = ($PageProd-1)*$messagesParPage;

 		
	 	$Article=mysql_query('SELECT * FROM Produit WHERE CategorieID = "'.$rowInstru['CategorieID'].'" ORDER BY "'.$rowInstru['Produit'].'" LIMIT '.$pageActuel.', '.$messagesParPage.'');
	 	
	 	echo "<DIV id=".$PageProd.">";
		while ($rowArticle=mysql_fetch_array($Article)) {
			
			$PicArt = mysql_fetch_array(mysql_query('SELECT * FROM ProduitPhoto WHERE ProduitID = "'.$rowArticle['ProduitID'].'"'));
			$Pic = substr($PicArt['File'],1,strlen($PicArt['File']));
			
			$Art = iconv("latin1", "UTF-8//TRANSLIT", $rowArticle['Produit']);
	 		echo '<Div align=left style="color:#FFF;border-radius: 10px;border-width:1px;border-style:solid;border-color:#000000;width:90%;background-image:url(Design/Opac.png);">';
	 		echo "<table style='color:#FFF;width:100%;'><tr><td rowspan=3 width=80><img src=".$Pic." width=80 height=80 style='border-radius: 10px;border-width:1px;border-style:solid;border-color:#000000;'></td><td align=left style='font-size:25;'>".$Art."</td></tr>";
	 		echo "<tr><td align=left style='font-style:italic;'>".$rowArticle['RefStock']."</td></tr><tr><td align=right style='font-size:25;font-weight:bold;'>".$rowArticle['PrixTTC']." Chf</td></tr></table></div><br>";
 		}
 		echo "</DIV>";
 		echo $PageProd;
 		}



Quelqu'un a une idée ? si il'y a besoin de plus de ressource n'hésitez pas ?
A voir également:

3 réponses

cgershon Messages postés 267 Date d'inscription lundi 21 avril 2008 Statut Membre Dernière intervention 25 janvier 2016 4
12 juil. 2012 à 13:22
Le bout de code ci dessous

Question simpliste ou est le <?php ?> ?
0
Regarde dans le grand bout de code, ce que j'ai mis en dessous est un extrait ^.^ Il y a donc <? et ?> qui sont en place ^.^
0
Personne n'a une idée ?
0