scooby545 Posted November 27, 2009 Share Posted November 27, 2009 hi, i have created a search bar for my site which records the users search data into a table. the table name is `websmart_searches` and its structure is : `key` bigint(20) NOT NULL auto_increment, `search` varchar(255) NOT NULL, `user` varchar(255) NOT NULL, `blocked` varchar(255) NOT NULL default 'no', `date` varchar(255) NOT NULL, `IP` varchar(255) NOT NULL, `time` varchar(255) NOT NULL, if the user searches for "phpfreaks" it will add a row like : INSERT INTO `websmart_searches` VALUES(6, 'phpfreaks', 'me', 'no', '27th November 2009', '192.168.1.1', '13:52pm'); duplicate entries are allowed and needed. what im trying to do is look at the data in the table and extract out the 10 most popular searches, based on an exact match ? does anyone know if this is possible using an sql query ? thanks in advance dave Quote Link to comment Share on other sites More sharing options...
burnside Posted November 27, 2009 Share Posted November 27, 2009 More of a MySql problem. But maybe some thing like this?? <?php // Make a MySQL Connection $query = "SELECT search, search(search) FROM websmart_searches GROUP BY search ORDER BY null LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo $row['search']. " - $". $row['search(search)']; echo "<br />"; } ?> Here the link where i got that from: http://www.tizag.com/mysqlTutorial/mysqlgroupby.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.