MySQL viewing saved searches Oct31 '05

One of the most useful functions in MySQL is the COUNT() function, which collectively grabs the total number of just about any 'result combination' you can think of.
For example, on a corporate site I am maintaining, I like to keep track of all searches submitted at the site, through our search box. I do this by having each search request entered into a database, at the time of the search.
This allows us to see common phrases being searched for, detect patterns, and adjust the site accordingly.
With the search terms all stored in a database - there are many different ways to view those search terms, for our own studies.
With SQL, we can query for those search terms, using useful criteria.
Below are some examples of how we can use SQL to view our saved searches database.
The most recent search requests:
SELECT * FROM saved_searches ORDER BY datetime DESC
The top 20, most recent search requests:
SELECT * FROM saved_searches ORDER BY datetime DESC LIMIT 20
The most common search requests:
SELECT searchterm, COUNT(*) AS 'Number of times searched' FROM saved_searches GROUP BY searchterm ORDER BY 'Number of times searched' DESC
The most common search requests, by a specific IP address:
SELECT searchterm, COUNT(*) AS 'Number of times searched', ip_address FROM saved_searches WHERE ip_address = '32.433.12.5' GROUP BY searchterm ORDER BY 'Number of times searched' DESC
As you can see, there are many different ways to view our saved search reqests. Depending on the extensiveness of the database table structure - the possibilities are almost endless.
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
- CSS Halloween costumes? Get creative!
- It’s hard remembering usernames, not passwords
- Football weekly blame game
Similar Entries
- Install Apache, PHP, MySQL on Windows (168 recent visits)
- MySQL search criteria - column alias (1027 recent visits)
- MySQL integer columns and display width (1060 recent visits)
- MySQL LEFT JOIN syntax (2722 recent visits)
- MySQL changing column types (685 recent visits)
- MySQL: enum or char(1)? (445 recent visits)
Stats
22 unique visits since August 2008
Recent Referrers (click)
- mysql detect patterns
- http://matthom.com/archive/200
- http://matthom.com/archive/200
- search
- mysql order ip-address
- mysql introduction save search
- http://matthom.com/archive/200
- common search requests
- MySQL recent search
- mysql order by recent
- mysql recent searches
- saving ips in mysql
- mysql search request
- mysql search request
- track number of searches mysql
- mysql search ip address
- search
- MySQL saving ip
- mysql order by most common