Se connecter avec
S'enregistrer | Connectez-vous

[PHP-MySql] ORDER BY quand plusieurs LIMIT

Dernière réponse : dans Programmation

Bonjour,

Voilà ! J'ai une question à vous poser... je bloque sur des requêtes sql... Ma table à un champ id auto_increment...

Je développe un site web pour mon père, j'ai donc créé une petite album photo, le problème est que les photos s'affiche par l'ordre d'entrer dans la base mysql et je voudrais que ce soit par id... voici le code qui permet l'affichage des images
  1. $p = $_GET['p'];
  2. if(empty($p)) { $p = 0; } else { $p = ($p-1)*12; }
  3. $j = ($p);
  4. echo '<tr>';
  5. $ss = ' SELECT * FROM `photos` LIMIT '.$j.', 4';
  6. $ll = mysql_query( $ss );
  7. while($data = mysql_fetch_array($ll))
  8. {
  9. echo '<td width="25%" align="center">
  10. <a href="box.php?width=1000&height=450&pic='.$data['id'].'" class="thickbox" target="_blank" title="Cliquez pour agrandir">
  11. <img src="image.php?width=210&height=300&image='.$data['large'].'" width="186px;"/></a>';
  12. if(admin(cachépoursecurité))
  13. {
  14. echo '<br /><a href="editpicture.php?mod='.$data['id'].'">Modifier</a><br /><a href="editpicture.php?del='.$data['id'].'">Supprimer</a>';
  15. }
  16. echo'</td>';
  17. }
  18. echo '</tr>';
  19. $j = ($p)+4;
  20. echo '<tr>';
  21. $ss = ' SELECT * FROM `photos` LIMIT '.$j.', 4';
  22. $ll = mysql_query( $ss );
  23. while($data = mysql_fetch_array($ll))
  24. {
  25. echo '<td width="25%" align="center">
  26. <a href="box.php?width=1000&height=450&pic='.$data['id'].'" class="thickbox" target="_blank" title="Cliquez pour agrandir">
  27. <img src="image.php?width=210&height=300&image='.$data['large'].'" width="186px;"/></a>';
  28. if(admin(cachépoursecurité))
  29. {
  30. echo '<br /><a href="editpicture.php?mod='.$data['id'].'">Modifier</a><br /><a href="editpicture.php?del='.$data['id'].'">Supprimer</a>';
  31. }
  32. echo'</td>';
  33. }
  34. echo '</tr>';
  35. $j = ($p)+8;
  36. echo '<tr>';
  37. $ss = ' SELECT * FROM `photos` LIMIT '.$j.', 4';
  38. $ll = mysql_query( $ss );
  39. while($data = mysql_fetch_array($ll))
  40. {
  41. echo '<td width="25%" align="center">
  42. <a href="box.php?width=1000&height=450&pic='.$data['id'].'" class="thickbox" target="_blank" title="Cliquez pour agrandir">
  43. <img src="image.php?width=210&height=300&image='.$data['large'].'" width="186px;"/></a>';
  44. if(admin(cachépoursecurité))
  45. {
  46. echo '<br /><a href="editpicture.php?mod='.$data['id'].'">Modifier</a><br /><a href="editpicture.php?del='.$data['id'].'">Supprimer</a>';
  47. }
  48. echo'</td>';
  49. }
  50. echo '</tr>';
  51. echo '</table>';

Autres pages sur : php mysql order plusieurs limit

Lassé par la pub ? Créez un compte
Expert Programmation

Je me demandais a quoi servait tes 3 requete SQL, je viens de comprendre, tu fais 3 ligne avec 4 image à chaque fois.

Tu t'y prend très mal enfait.

La boucle est bien pensé, sauf qu'enfait, il te faut faire une boucle supplémentaire (avec un $i par exemple, que tu en rajoute +1) à chaque affichage, et une fois arrivé à 4, tu rajoute un </tr><tr> pour retourner a la ligne, et tu remet $i à 0. et ainsi de suite, de ce résultat tu n'aura qu'une requete SQL.


tu peut t'appuyer sur la deuxieme réponse de ce lien :
http://www.commentcamarche.net/forum/affich-3452040-php...

et tu as modulo :
http://forum.phpfrance.com/faq-tutoriels/nombre-colonne...

tu verra le principe.;)
Lassé par la pub ? Créez un compte
Tom's guide dans le monde