How do I show todays top search list?
I owns a website which is doing lots of searches per day. these search results are stored in my MySQL databse. what I want is I want retrieve toda开发者_高级运维y's top searches from MySQL limit to 20 and display in my website. how do I do this with PHP & MySQL??
Thanks
Mathew
You will need to do something looked like this:
$today = date("F j, Y"); // NOTICE, you have to format your date like you have @ database field
$q = " SELECT search_string_field, count(search_string_field) as count
FROM search_results_table
WHERE search_date_field = '$today'
ORDER BY count DESC
GROUP BY search_string_field
LIMIT 20";
$results = mysql_query($q);
and fetch the results after executing query
You'll need to store the time for each search. With that you can query the database (using date ranges and limit) for the popular searches within a time period or you can do it with PHP.
What metric do you have for storing searches. Do you store every search term, or update a number if the term was used more than once?
If you have a number of terms searched
$query = 'SELECT * FROM searches ORDER BY searched DESC LIMIT 20';
But I think you need to give more info... what does your table look like?
精彩评论