Never lose hope. You never know what tomorrow may bring.
SELECT * , COUNT( ref ) AS occurances FROM table GROUP BY ref ORDER BY occurances DESC
<?php $str="hi how how r you how?"; echo substr_count($str, 'how'); ?>