I have a script where when somebody searches for something, it goes into a table called “searches”, and on my website I have a “recent searches” section that displays what people are searching for.
To avoid duplicate searches in the database, it doesn’t re-add the keyword, but it does increase the “views” of that search.
Problem is my code grabs the search cloud like this:
mysql_query("SELECT keyword FROM searches ORDER BY id DESC LIMIT 0,$amount");
How can I set this up so, when somebody searches for a keyword that is already in the database so that the keyword shows up again on the websites recent searches section?
Maybe you can add a field called updated_at.
So when a user searches for a keyword that is already in the database, you will also update the updated_at field along with the view count.
Then you can sort by that field for your recent searches.