I am using MYSQL MYISAM and php version 5.4.16,MYISAM and am doing a fulltext search based on the (product_name) column and i want to randomize the result but the problem is rand()not giving the random values.

I tried something like this:

SELECT product_name,main_cat_id,sub_cat_id,prod_cat_id,prod_short_desc,com_id,product_id,product_ratings, min_order_quantity, fob,country_id,company_name,attributes,attr_values,verify,image,product_additionals , MATCH (product_name)AGAINST ('"girls top"'IN BOOLEAN MODE) AS relevance, MATCH (product_name)AGAINST ('girl* +top'IN BOOLEAN MODE) AS relevance1 FROM pep_browse_com_prods WHERE (MATCH (product_name) AGAINST ('"girls top"'IN BOOLEAN MODE) OR MATCH (product_name) AGAINST ('girl +top*'IN BOOLEAN MODE)) AND STATUS = '0' AND display = '0' ORDER BY relevance DESC,relevance1 DESC,RAND() limit 20

I want to set the relevance first then i want the random values of rest columns.

I'm not sure but maybe the RAND() should be something your select returns. Just a piece of thought, though. Something like

SELECT RAND() AS rand_nr
ORDER BY rand_nr DESC

Just a question though: what use does it have to create a random order, after you've already ordered by relevance?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.