[SQL] mise en forme d'une requete sql
bonjour,
j'ai une page où sont affichés les resultats d'une requete, je voudrais juste les mettre dans un tableau de type 3 colonnes mais je ne sais pas commment faire :cry:.
Pour l'instant, il m'affiche un produit par ligne.
mon code est le suivant :
Code:
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| <?php
include("../configuration.inc.php");
if (!isset($_GET['catid'])) { $catid = 0;} else {$catid = intval($_GET['catid']);}
$qid_c = recupere_sous_categorie($catid);
$DOC_TITLE = "Peter Span Design";
include("$repertoire_modele/haut.php");
?>
<div class="normal" valign="top"style="border-bottom: 1px dotted grey;text-transform : uppercase;">
<?php affiche_arbre_categorie($catid) ?></div>
<?php
$sqlcat = "SELECT image, description FROM peel_categories WHERE id = '".$catid."'";
$rescat = mysql_query($sqlcat);
$objcat = mysql_fetch_object($rescat);
if ($rescat) {
if (mysql_num_rows($rescat) > 0) {
echo "<div align=\"center\" class=\"normal\">";
if (!empty($objcat->image)) {
echo "<img src=\"$wwwroot/upload/".$objcat->image."\" width=\"150\" align=\"center\">";
}
echo "<br /><br >".stripslashes($objcat->description);
echo "</div>";
}
}
if ($qid_c) {
if (mysql_num_rows($qid_c) == 0) {
echo "";
} else {
$nb_cellules = mysql_num_rows($qid_c);
$nb_colonnes = 3;
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td class=\"normal\">";
echo "<strong>Dans cette rubrique :</strong>";
echo "</td></tr>";
while ($cat = mysql_fetch_array($qid_c)) { ?>
<tr valign="top"><td class="normal">
<a class="normal" href="<?php echo $_SERVER['PHP_SELF']?>?catid=<?php echo $cat['id'] ?>"><?php echo $cat['nom'] ?></a>
</td></tr>
<?php }
echo "<tr><td><img src=$wwwroot/images/blank.gif width=\"1\" height=\"10\" border=\"0\" alt=\"\" /></td></tr></table>";
}
} else {
echo "";
}
?>
<?php
$nb = 12; //nombre d'enregistrement par page
if (!isset($_GET['start'])) {$start=0;} else {$start = $_REQUEST['start'];}
// Récupération et affichage des données
$sql = "SELECT p.id, p.nom, p.image1
FROM peel_produits_categories pc, peel_produits p LEFT JOIN peel_ecotaxes e ON (p.id_ecotaxe = e.id) WHERE p.id = pc.produit_id AND pc.categorie_id = '".intval($catid)."'
AND p.etat = '1' ORDER BY p.prix LIMIT $start,$nb";
$result=mysql_query($sql) or die('Une erreur de connexion à la base s est produite ' . __LINE__ . '.<p>' . mysql_error());
if (mysql_num_rows($result) == 0) {
if (mysql_num_rows($qid_c) == 0) {
echo "aucun produit disponible dans cette catégorie";
}
} else {
echo "<table colspan=\"3\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
while($prod=mysql_fetch_array($result))
{
?>
<tr>
<td width="200" height="200" align="center" valign="middle" class="normal" colspan="3">
<?php
echo "<a class=\"normal\" href=\"$wwwroot/achat/produit_details.php?id=".$prod['id']."&catid=".$catid."\">";
echo html_entity_decode($prod['nom'])."<br />";
if ($prod['image1'] != "") { ?>
<img src="<?php echo $repertoire_images?>/<?php echo $prod['image1'] ?>" alt="" width="150" border="0" align="center" /></a>
<?php } else {?>
<img src="<?php echo $wwwroot?>/images/photo-non-disponible.gif" align="center" alt="photo non disponible" />
<?php }?>
</a> </td>
<td class="normal" colspan="3">
<?php } ?>
<!-- Début du formulaire -->
</td></tr>
<tr>
<td align="center" class="normal" colspan="6">
<?php
}
//Boutons précédent et suivant
if($start)
{echo ("<a class=\"normal\" href=\"$wwwroot/achat/index.php?catid=".$catid."&start=".($start-$nb)."\">Page précédente</a>");}
$result=mysql_query("SELECT COUNT(*) FROM peel_produits p, peel_produits_categories pc WHERE p.id = pc.produit_id AND pc.categorie_id = $catid AND p.etat = 1");
$row=mysql_fetch_row($result);
if($row[0]>($start+$nb))
{
if($start)
{echo (" / ");}
echo ("<a class=\"normal\" href=\"$wwwroot/achat/index.php?catid=".$catid."&start=".($start+$nb)."\">Page suivante</a>");
}
echo ("<br />");
//Affichage des pages
if($row[0]>$nb) {// le nombre d'enreg. est > au nb de lignes d'affichage ?
echo ("Page :");
for($index=0;($index*$nb)<$row[0];$index++) // oui alors on affiche les numéros de pages
{
?>
<b><a class="normal" href="<?php echo $_SERVER['PHP_SELF']."?catid=".$catid."&start=".$index*$nb; ?>"><?php echo $index+1; ?></a></b>
<?php
}
}
echo "</td></tr></table>";
include("$repertoire_modele/bas.php");
/******************************************************************************
* FONCTIONS
*****************************************************************************/
function recupere_sous_categorie($catid=0) {
/* Récupère le nom et la description de toutes les sous-catégories de celle-ci */
$qid = mysql_query("SELECT id, nom, description, parent_id FROM peel_categories WHERE parent_id = $catid AND id > 0 AND etat = 1") or DIE('Une erreur de connexion à la base s est produite ' . __LINE__ . '.<p>' . MYSQL_ERROR());
return $qid;
}
?> |
Toute aide est bienvenue :lol: