Tri de données mysql en pages avec tris

Résolu
juldu33 -  
ThEBiShOp Messages postés 8411 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

Je me suis créé un site il y a quelque temps sur lequel je met des musiques. Au début c'était simple car je mettais tout sur la même page par ordre d'ajout mais maintenant j'ai 7 pages avec possibilité de classer par date d'ajout et par ordre alphabétique. Mais je me retrouve avec un code énorme (200 lignes juste pour ça) et dès que je veux rajouter une page je m'embête. Je voudrais donc le simplifier.

Voilà un extrait pour 2 pages :

page.php
<?php
if ($_GET['tri'] == "date")
{
	if ($_GET['p'] == "1")
	{
		echo "Page
	1
	<a href='zic.php?p=2&tri=date'>2</a> 
	<a href='zic.php?p=3&tri=date'>3</a> 
	<a href='zic.php?p=4&tri=date'>4</a> 
	<a href='zic.php?p=5&tri=date'>5</a>
	<a href='zic.php?p=6&tri=date'>6</a>
	<a href='zic.php?p=7&tri=date'>7</a>";
		$retour = mysql_query('SELECT * FROM zic ORDER BY id DESC LIMIT 0,6');
	}

	elseif ($_GET['p'] == "2")
	{
		echo "Page
	<a href='zic.php?p=1&tri=date'>1</a> 
	2
	<a href='zic.php?p=3&tri=date'>3</a> 
	<a href='zic.php?p=4&tri=date'>4</a> 
	<a href='zic.php?p=5&tri=date'>5</a>
	<a href='zic.php?p=6&tri=date'>6</a>
	<a href='zic.php?p=7&tri=date'>7</a>";
		$retour = mysql_query('SELECT * FROM zic ORDER BY id DESC LIMIT 6,6');
	}
        echo "<br/><br/><a href='zic.php?p=1&amp;tri=alpha'>Trier par titre</a>";
}

elseif ($_GET['tri'] == "alpha")
{
	if ($_GET['p'] == "1")
	{
		echo "Page
	1
	<a href='zic.php?p=2&tri=alpha'>2</a> 
	<a href='zic.php?p=3&tri=alpha'>3</a> 
	<a href='zic.php?p=4&tri=alpha'>4</a> 
	<a href='zic.php?p=5&tri=alpha'>5</a>
	<a href='zic.php?p=6&tri=alpha'>6</a>
	<a href='zic.php?p=7&tri=alpha'>7</a>";
		$retour = mysql_query('SELECT * FROM zic ORDER BY titre ASC LIMIT 0,6');
	}

	elseif ($_GET['p'] == "2")
	{
		echo "Page
	<a href='zic.php?p=1&tri=alpha'>1</a> 
	2
	<a href='zic.php?p=3&tri=alpha'>3</a> 
	<a href='zic.php?p=4&tri=alpha'>4</a> 
	<a href='zic.php?p=5&tri=alpha'>5</a>
	<a href='zic.php?p=6&tri=alpha'>6</a>
	<a href='zic.php?p=7&tri=alpha'>7</a>";
		$retour = mysql_query('SELECT * FROM zic ORDER BY titre ASC LIMIT 6,6');
	}
        echo "<br/><br/><a href='zic.php?s="; echo $_GET['s']; echo "&p=1&amp;tri=date'>Trier par date</a>";
}



zic.php
<?php include "include/pages.php" ?>

<br/>
<br/>
______________________________________________
<br/><br/>
<?php


while ($donnees = mysql_fetch_array($retour))
{

	$titre = stripslashes($donnees['titre']);
	echo $titre;
	echo "<br/>";
	$zic = nl2br(stripslashes($donnees['zic'])); 
    ?>
	<br/>
	<object width="220" height="55">
		<param name="movie" value="http://cdn-files.deezer.com/swf/singlePlayer-v10.swf?idSong=2160741&colorBackground=0x555552&textColor1=0xFFFFFF&colorVolume=0x39D1FD&autoplay=0">
		</param>
		<embed src="http://cdn-files.deezer.com/swf/singlePlayer-v10.swf?idSong=<?php echo"$zic"; ?>&colorBackground=0x555552&textColor1=0xFFFFFF&colorVolume=0x00C7F2&autoplay=0" type="application/x-shockwave-flash" width="220" height="55">
		</embed>
	</object>
<br/>
    

______________________________________________
<br/><br/>
<?php
} 
?>
<br/>
<?php include "include/pages.php" ?>



Merci d'avance
A voir également:

5 réponses

ThEBiShOp Messages postés 8411 Date d'inscription   Statut Contributeur Dernière intervention   1 566
 
Bonjour,

tu as un réel problème ou tu veux juste qu'on te fasse tout à ta place ?
0
juldu33
 
Non je voudrais juste savoir une méthode j'avais pensé à mettre des variable dans le
$retour = mysql_query('SELECT * FROM zic ORDER BY id DESC LIMIT 0,6');

par exemple
$retour = mysql_query('SELECT * FROM zic ORDER BY $order DESC LIMIT $limit');

mais il prend pas ça comme une variable et n'affiche rien du tout
Après pour l'affichage du numéro des pages j'aurais pu faire plus simple en mettant tout pareil mais après on sait pas sur quelle page on est
enfin c'est un vrai casse tete
0
Alain_42 Messages postés 5361 Date d'inscription   Statut Membre Dernière intervention   894
 
Vas voir sur G..... "pagination php"
0
juldu33
 
merci c'est ce que je cherchais (j'avais regardé sur g... mais je savais pas quoi taper lol)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ThEBiShOp Messages postés 8411 Date d'inscription   Statut Contributeur Dernière intervention   1 566
 
tu peux faire quelque chose du genre :


$page = $_GET['page'];
$limit = page*6;

$retour = mysql_query('SELECT * FROM zic ORDER BY "'.order.'" DESC LIMIT "'.$limit.'"6,');

0