PHP MySQL Trier par mots-clés
Le mot-clé ORDER BY est utilisé pour trier les données dans un jeu d'enregistrements.
La clause ORDER PAR mots-clés
Le mot-clé ORDER BY est utilisé pour trier les données dans un jeu d'enregistrements.
Le mot-clé ORDER BY tri des dossiers dans l'ordre croissant par défaut.
Si vous voulez trier les enregistrements dans un ordre décroissant, vous pouvez utiliser le mot-clé DESC.
Syntaxe
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
FROM table_name
ORDER BY column_name(s) ASC|DESC
Pour en savoir plus sur SQL, s'il vous plaît visitez notre tutoriel SQL .
Exemple
L'exemple suivant sélectionne toutes les données stockées dans l'affaire «personne» de table, et trie les résultats par le terme «âge» de la colonne:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons ORDER BY age");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
echo " " . $row['LastName'];
echo " " . $row['Age'];
echo "<br />";
}
mysql_close($con);
?>
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons ORDER BY age");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
echo " " . $row['LastName'];
echo " " . $row['Age'];
echo "<br />";
}
mysql_close($con);
?>
La sortie du code ci-dessus sera:
Glenn Quagmire 33
Peter Griffin 35
Peter Griffin 35
Trier par deux colonnes
Il est également possible de commander par plus d'une colonne. Lors de la commande par plus d'une colonne, la deuxième colonne est utilisée uniquement si les valeurs de la première colonne sont égaux:
SELECT column_name(s)
FROM table_name
ORDER BY column1, column2
FROM table_name
ORDER BY column1, column2
I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you?
ReplyDeletePlz respond as I'm looking to create my own blog and would like to know where u got this from. cheers
Look at my web-site; toe nail fungus treatments
I'm impressed, I must say. Rarely do I encounter a blog that's equally educative and amusing, and let me tell you, you have hit the nail on the head.
ReplyDeleteThe issue is something not enough people are speaking
intelligently about. I'm very happy that I stumbled across this in my search for something regarding this.
my blog ... wood floors
Also see my page > http://www.flooranddecoroutlets.com/hardwood-solid.html
Why visitors still make use of to read news papers when in this technological globe all is accessible on web?
ReplyDeletehardwood floors installation
Also visit my website: hardwood floor
Thanks in favor of sharing such a pleasant thought, paragraph is good, thats why i have read it
ReplyDeletefully
Visit my blog - affordable hardwood flooring
my website: http://www.flooranddecoroutlets.com/hardwood-solid.html
Nice weblog right here! Also your web site lots up
ReplyDeletefast! What host are you the use of? Can I
am getting your affiliate link on your host? I want my web site loaded up as fast as yours lol
my web blog ... zetaclear side effects
Also see my page - nail fungus zetaclear
Good article. I definitely appreciate this site.
ReplyDeleteContinue the good work!
Here is my website :: just click the following internet page
Good article. I definitely appreciate this site.
ReplyDeleteContinue the good work!
Here is my blog: just click the following internet page
Also see my site > http://www.maidbrigade.com
Hi there! This is kind of off topic but I need some advice from an established blog.
ReplyDeleteIs it difficult to set up your own blog?
I'm not very techincal but I can figure things out pretty fast. I'm thinking
about setting up my own but I'm not sure where to begin. Do you have any ideas or suggestions? Thanks
Here is my page; poll.efiree.com
My website > https://silpac.monsoonhub.org/
Hello to all, since I am truly keen of reading this blog's post to be updated regularly. It contains nice information.
ReplyDeleteMy page - does natox work