PHP MySQL Trier par mots-clés


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
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);
?>
La sortie du code ci-dessus sera:
Glenn Quagmire 33
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

9 commentaires:

  1. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you?
    Plz 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

    ReplyDelete
  2. 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.
    The 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

    ReplyDelete
  3. Why visitors still make use of to read news papers when in this technological globe all is accessible on web?

    hardwood floors installation

    Also visit my website: hardwood floor

    ReplyDelete
  4. Thanks in favor of sharing such a pleasant thought, paragraph is good, thats why i have read it
    fully

    Visit my blog - affordable hardwood flooring
    my website: http://www.flooranddecoroutlets.com/hardwood-solid.html

    ReplyDelete
  5. Nice weblog right here! Also your web site lots up
    fast! 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

    ReplyDelete
  6. Good article. I definitely appreciate this site.

    Continue the good work!

    Here is my website :: just click the following internet page

    ReplyDelete
  7. Good article. I definitely appreciate this site.
    Continue the good work!

    Here is my blog: just click the following internet page
    Also see my site > http://www.maidbrigade.com

    ReplyDelete
  8. Hi there! This is kind of off topic but I need some advice from an established blog.
    Is 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/

    ReplyDelete
  9. Hello to all, since I am truly keen of reading this blog's post to be updated regularly. It contains nice information.

    My page - does natox work

    ReplyDelete

HELLO VISITORS THANKS FOR YOUR VISIT AND COMMENT