par
dan4 » 31 mars 2010, 18:01
Bonjour,
je regarde de nombreux tutos, mais je galère pas mal pour afficher des résultats par par page.
Voici le code que j'ai mis en place, mais à part ma première ligne qui s'affiche correctement, après j'ai tout qui s'affiche, et quelque soit l'ndroit où j'essaie de mettre un "LIMIT" ça marche plus :
<?php
//Information pour la connection à le DB
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'vol';
//Connection à la BDD
$link = mysql_connect ($host,$user,$pass) or die ('Erreur : '.mysql_error() );
mysql_select_db($db) or die ('Erreur :'.mysql_error());
$nombre = 5; // on va afficher 5 résultats par page.
if (!isset($limite)) $limite = 0; // si on arrive sur la page pour la première fois
// on met limite à 0.
$choix_critere=$_GET['critere'];
$path_parts = pathinfo($_SERVER['PHP_SELF']);
$page = $path_parts['basename'];
$select = 'SELECT DISTINCT critere FROM criteres WHERE criteres.critere="'.$choix_critere.'" LIMIT '.$limite.','.$nombre;
$result = mysql_query($select,$link) or die ('Erreur : '.mysql_error() );
$row = mysql_fetch_row($result);
$total = $row[0];
/*Requete mysql*/
echo "<br/>";
echo '<li class="pays"><img src="images/pt_logo_webcam_01.png" /> Vous regardez des webcam situées en '.$choix_critere.'</li>';
echo "<br/>";
if(isset($_GET["critere"]))
{
$image = mysql_query("SELECT DISTINCT webcam.url as url, webcam.ville as ville, webcam.commentaire as commentaire, criteres.critere as critere, pays.drapeaux FROM webcam LEFT JOIN criteres ON (webcam.id_critere = criteres.id) LEFT JOIN pays ON (webcam.id_pays = pays.id) WHERE criteres.critere='".$_GET['critere']."'")or die(mysql_error());
while ($affichage = mysql_fetch_assoc($image) )
//while ($row = mysql_fetch_row($result) )
{
echo '<div class="img">';
echo $affichage['ville'];
echo ' <img src="drapeaux_pt/'.$affichage['drapeaux'].'" width="16" height="11">';
echo "<br />";
echo '<img src="'.$affichage['url'].'" width="190" height="143">';
echo "<br />";
//echo $affichage['commentaire'];
echo "</div>";
}
echo "<br />";
}
/*Deconnexion de MySQL*/
mysql_close();
?>
Merci de votre aide
Pour le page par page, j'ai trouvé ce code que j'ai été capable d'adapter ma mon site.
voici le lien :
http://seebz.net/12-creer-un-systeme-de-pagination.html
Il est super fonctionnel et en plus, il est beau.
C'est pas facile d'avoir de l'aide en général lié à notre cas. Mais je pense que ça va surement réponse à votre problème.
Moi, le mien, mon problème est d'afficher par critère en tenant compte de la pagination.
A partir d'un formulaire, envoyer à une requête pour afficher par catégorie
si des fois que voici mon code :
...
?>
<form name="ici">
<select name="ici" size="1">
<option value="ametis">Ametis</option>
<option value="zzz">zzz</option>
</select>
<input type="submit" value="Envoyer">
</form>
<?php
if(!empty($_POST['ici']))
{
if( $_POST['ici'] == "ici" ) // On sélectionne tout
{
$sql = "SELECT * FROM produits ORDER BY noart ASC LIMIT $limit_start,$pagination";
}
else // Seulement une catégorie
{
$sql = "SELECT * FROM produits WHERE nocat={$_POST['ici']} ORDER BY noart ASC LIMIT $limit_start,$pagination";
}
}
else
{
$sql = "SELECT * FROM produits ORDER BY noart LIMIT $limit_start,$pagination";
}
$req = mysql_query($sql,$db) or die(mysql_error());
...
[quote="Romuald632"]Bonjour,
je regarde de nombreux tutos, mais je galère pas mal pour afficher des résultats par par page.
Voici le code que j'ai mis en place, mais à part ma première ligne qui s'affiche correctement, après j'ai tout qui s'affiche, et quelque soit l'ndroit où j'essaie de mettre un "LIMIT" ça marche plus :
[php]
<?php
//Information pour la connection à le DB
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'vol';
//Connection à la BDD
$link = mysql_connect ($host,$user,$pass) or die ('Erreur : '.mysql_error() );
mysql_select_db($db) or die ('Erreur :'.mysql_error());
$nombre = 5; // on va afficher 5 résultats par page.
if (!isset($limite)) $limite = 0; // si on arrive sur la page pour la première fois
// on met limite à 0.
$choix_critere=$_GET['critere'];
$path_parts = pathinfo($_SERVER['PHP_SELF']);
$page = $path_parts['basename'];
$select = 'SELECT DISTINCT critere FROM criteres WHERE criteres.critere="'.$choix_critere.'" LIMIT '.$limite.','.$nombre;
$result = mysql_query($select,$link) or die ('Erreur : '.mysql_error() );
$row = mysql_fetch_row($result);
$total = $row[0];
/*Requete mysql*/
echo "<br/>";
echo '<li class="pays"><img src="images/pt_logo_webcam_01.png" /> Vous regardez des webcam situées en '.$choix_critere.'</li>';
echo "<br/>";
if(isset($_GET["critere"]))
{
$image = mysql_query("SELECT DISTINCT webcam.url as url, webcam.ville as ville, webcam.commentaire as commentaire, criteres.critere as critere, pays.drapeaux FROM webcam LEFT JOIN criteres ON (webcam.id_critere = criteres.id) LEFT JOIN pays ON (webcam.id_pays = pays.id) WHERE criteres.critere='".$_GET['critere']."'")or die(mysql_error());
while ($affichage = mysql_fetch_assoc($image) )
//while ($row = mysql_fetch_row($result) )
{
echo '<div class="img">';
echo $affichage['ville'];
echo ' <img src="drapeaux_pt/'.$affichage['drapeaux'].'" width="16" height="11">';
echo "<br />";
echo '<img src="'.$affichage['url'].'" width="190" height="143">';
echo "<br />";
//echo $affichage['commentaire'];
echo "</div>";
}
echo "<br />";
}
/*Deconnexion de MySQL*/
mysql_close();
?>
[/php]
Merci de votre aide[/quote]
Pour le page par page, j'ai trouvé ce code que j'ai été capable d'adapter ma mon site.
voici le lien :
http://seebz.net/12-creer-un-systeme-de-pagination.html
Il est super fonctionnel et en plus, il est beau.
C'est pas facile d'avoir de l'aide en général lié à notre cas. Mais je pense que ça va surement réponse à votre problème.
Moi, le mien, mon problème est d'afficher par critère en tenant compte de la pagination.
A partir d'un formulaire, envoyer à une requête pour afficher par catégorie
si des fois que voici mon code :
[php]
...
?>
<form name="ici">
<select name="ici" size="1">
<option value="ametis">Ametis</option>
<option value="zzz">zzz</option>
</select>
<input type="submit" value="Envoyer">
</form>
<?php
if(!empty($_POST['ici']))
{
if( $_POST['ici'] == "ici" ) // On sélectionne tout
{
$sql = "SELECT * FROM produits ORDER BY noart ASC LIMIT $limit_start,$pagination";
}
else // Seulement une catégorie
{
$sql = "SELECT * FROM produits WHERE nocat={$_POST['ici']} ORDER BY noart ASC LIMIT $limit_start,$pagination";
}
}
else
{
$sql = "SELECT * FROM produits ORDER BY noart LIMIT $limit_start,$pagination";
}
$req = mysql_query($sql,$db) or die(mysql_error());
...
[/php]