- <?
- /*************************************************************************
- * @Auteur: Legion
- * @Script: Afficher le résultat d'une requête sur plusieures pages.
- * @Version: 1.0
- * @Description: Il est souvent difficile que de gérer le résultat d'une
- * requête plus ou moins complexe sur une même page. Ce script montre
- * comment ce problème peut être contourné.
- * @Date: Jeudi 6 Février
- **************************************************************************/
-
- //Connection à la base.
- include("connect.inc");
- $base = mysql_select_db("ma_base");
-
- // Récupérer la variable $debut de page en page (PHP version 4)
- $debut = $HTTP_GET_VARS["debut"];
- if(!$debut) {
- $debut = "0";
- }
-
- // Requête native - Notons également que le paramètre '4' de la clause LIMIT servira à dénombrer le nombre
- // d'éléments par page.
- $sql = "SELECT * FROM ma_table a, ma_table2 b, ma_table3 c WHERE a.champ1 = b.champ1 AND a.champ2 = b.champ2 ORDER BY 'champ1' ASC LIMIT $debut,4";
- $requete = mysql_query($sql) or die(mysql_error());
-
- // Comptage du nombre de ligne concernées par la requête
- $nb_resultats = mysql_num_rows($requete);
-
- // Boucle d'affichage
- while($row = mysql_fetch_object($requete)) {
- $prixFrancs = round($row -> champ1 * '6,55957');
- echo '<tr><td width="150" border="1" bordercolor="#ffffff"><p><b><font color="#FF5B00">';
- echo $row -> champ2;
- echo '</font></b></p></td><td width="200" border="1" bordercolor="#ffffff"><p align="center">';
- echo $row -> champ3;
- echo ' jours</font></b></p></td><td width="100" border="1" bordercolor="#ffffff"><p align="center">';
- echo '<a href="fiche_tech.php?id=';
- echo $row -> num_champ;
- echo '" target="iarticles">Voir</a>';
- echo '</td></tr><tr><td width="150" border="1" bordercolor="#ffffff"><img src="img/vignettes/';
- echo $row -> champ4;
- echo '.gif"></td><td width="200" border="1" bordercolor="#ffffff"><p align="center">Notre prix:';
- echo $row -> champ5;
- echo ' ? / ';
- echo $prixFrancs;
- echo ' Frcs.</p></td></tr>';
- echo '<tr><td align="center" colspan="3" width="450" border="1" bordercolor="#ffffff">';
- echo '<hr width="400" size="1" NOSHADE color="#B9B9B9"></td></tr>';
- }
-
- // Comptons le nombre total de lignes.
- $sql_total = "SELECT * FROM tab_ecran";
- $requete_total = mysql_query($sql_total);
- $total_resultats = mysql_num_rows($requete_total);
-
- // Bouton Précédent
- if($debut != "0" AND ($nb_resultats < "5" OR ($debut+4) == $total_resultats)) {
- echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
- echo '<tr><td width="225" align="left">';
- $debut = $debut - 4;
- echo '<a href="ecrans.php?debut='.$debut.'">[ << Précédents ]</a>';
- echo '</td><td width="225" align="right"></td></tr></table></td></tr>';
- // Bouton Suivant et Précédent
- } elseif($nb_resultats == "5" AND $debut != "0") {
- echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
- echo '<tr><td width="225" align="left">';
- $debut = $debut - 4;
- echo '<a href="ecrans.php?debut='.$debut.'">[ << Précedents ]</a>';
- echo '</td><td width="225" align="right">';
- $debut = $debut + 4;
- echo '<a href="ecrans.php?debut='.$debut.'">[ Suivants >> ]</a>';
- echo '</td></tr></table></td></tr>';
- // Bouton Suivant
- } elseif($total_resultats != $nb_resultats AND ($debut == "0" OR ($debut + 4) != $total_resultats)) {
- $debut = $debut + 4;
- echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
- echo '<tr><td width="225" align="left"></td><td width="225" align="right">';
- echo '<a href="ecrans.php?debut='.$debut.'">[ Suivants >>]</a>';
- echo '</td></tr></table></td></tr>';
- }
- ?>
<?
/*************************************************************************
* @Auteur: Legion
* @Script: Afficher le résultat d'une requête sur plusieures pages.
* @Version: 1.0
* @Description: Il est souvent difficile que de gérer le résultat d'une
* requête plus ou moins complexe sur une même page. Ce script montre
* comment ce problème peut être contourné.
* @Date: Jeudi 6 Février
**************************************************************************/
//Connection à la base.
include("connect.inc");
$base = mysql_select_db("ma_base");
// Récupérer la variable $debut de page en page (PHP version 4)
$debut = $HTTP_GET_VARS["debut"];
if(!$debut) {
$debut = "0";
}
// Requête native - Notons également que le paramètre '4' de la clause LIMIT servira à dénombrer le nombre
// d'éléments par page.
$sql = "SELECT * FROM ma_table a, ma_table2 b, ma_table3 c WHERE a.champ1 = b.champ1 AND a.champ2 = b.champ2 ORDER BY 'champ1' ASC LIMIT $debut,4";
$requete = mysql_query($sql) or die(mysql_error());
// Comptage du nombre de ligne concernées par la requête
$nb_resultats = mysql_num_rows($requete);
// Boucle d'affichage
while($row = mysql_fetch_object($requete)) {
$prixFrancs = round($row -> champ1 * '6,55957');
echo '<tr><td width="150" border="1" bordercolor="#ffffff"><p><b><font color="#FF5B00">';
echo $row -> champ2;
echo '</font></b></p></td><td width="200" border="1" bordercolor="#ffffff"><p align="center">';
echo $row -> champ3;
echo ' jours</font></b></p></td><td width="100" border="1" bordercolor="#ffffff"><p align="center">';
echo '<a href="fiche_tech.php?id=';
echo $row -> num_champ;
echo '" target="iarticles">Voir</a>';
echo '</td></tr><tr><td width="150" border="1" bordercolor="#ffffff"><img src="img/vignettes/';
echo $row -> champ4;
echo '.gif"></td><td width="200" border="1" bordercolor="#ffffff"><p align="center">Notre prix:';
echo $row -> champ5;
echo ' ? / ';
echo $prixFrancs;
echo ' Frcs.</p></td></tr>';
echo '<tr><td align="center" colspan="3" width="450" border="1" bordercolor="#ffffff">';
echo '<hr width="400" size="1" NOSHADE color="#B9B9B9"></td></tr>';
}
// Comptons le nombre total de lignes.
$sql_total = "SELECT * FROM tab_ecran";
$requete_total = mysql_query($sql_total);
$total_resultats = mysql_num_rows($requete_total);
// Bouton Précédent
if($debut != "0" AND ($nb_resultats < "5" OR ($debut+4) == $total_resultats)) {
echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td width="225" align="left">';
$debut = $debut - 4;
echo '<a href="ecrans.php?debut='.$debut.'">[ << Précédents ]</a>';
echo '</td><td width="225" align="right"></td></tr></table></td></tr>';
// Bouton Suivant et Précédent
} elseif($nb_resultats == "5" AND $debut != "0") {
echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td width="225" align="left">';
$debut = $debut - 4;
echo '<a href="ecrans.php?debut='.$debut.'">[ << Précedents ]</a>';
echo '</td><td width="225" align="right">';
$debut = $debut + 4;
echo '<a href="ecrans.php?debut='.$debut.'">[ Suivants >> ]</a>';
echo '</td></tr></table></td></tr>';
// Bouton Suivant
} elseif($total_resultats != $nb_resultats AND ($debut == "0" OR ($debut + 4) != $total_resultats)) {
$debut = $debut + 4;
echo '<tr><td width="450" colspan="3" border="0"><table width="450" border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td width="225" align="left"></td><td width="225" align="right">';
echo '<a href="ecrans.php?debut='.$debut.'">[ Suivants >>]</a>';
echo '</td></tr></table></td></tr>';
}
?>