lundi 3 octobre 2016

Random like order with mysql and PHP

I use PHP and Mysql. I have a table that looks kind of like this:

id   title
----------
1    my title
2    another title
3    The last title

Now I want to select them with a random like order.

  • I will need to use LIMIT because of the query size.
  • The random like order should always be the same random order every time.

Example result, every time

3   The last title
1   my title
2   another title

Do another query run:

3   The last title
1   my title
2   another title

The same random like result appear.

Possible solutions

  • Add a real random number stored as a new column generated by insert.
  • Some fancy SELECT query that does some magic.
  • Something else?

Why I want this is that I insert products, first from one site, then from another. In the result I want to present them as a mix.




Aucun commentaire:

Enregistrer un commentaire