28 January 2012

sort by occurence of anyvalue in a column

SELECT * , COUNT( ref ) AS occurances FROM table GROUP BY ref ORDER BY occurances DESC

count the occurence of a word in a string

<?php
$str="hi how how r you how?";
echo substr_count($str, 'how');
?>

this will give outpus as "3"
since "how" occured in the string 3 times.