php - How to write a query that selects 9 rows randomly from database?

652
SELECT * FROM tbl_specialisation
     WHERE LENGTH(spec_specialise) < 20 ORDER BY spec_specialise LIMIT 9 

add to this query

816

Answer

Solution:

"SELECT * FROMtbl_specialisationWHERE LENGTH(spec_specialise) < 20 ORDER BY RAND() LIMIT 9 ";

654

Answer

Solution:

USEORDER BY RAND()

$sql= "SELECT * FROM `tbl_specialisation`WHERE LENGTH(spec_specialise) < 20 ORDER BY RAND() LIMIT 9 ";
151

Answer

Solution:

Your question is not clear because you are asking 9 random fields but in SQL query you are trying to get 9 records. If you want to get 9 records from table then use following.

$sql= "SELECT * FROM `tbl_specialisation`WHERE LENGTH(spec_specialise) < 20 ORDER BY RAND() LIMIT 9 ";  

People are also looking for solutions to the problem: php - show custom fields data in next and previous link in wordpress

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.