473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is it possible to create a "most popular" search?

In my website, it would be very useful to have a most popular search. But i have know idea how I would do it. When a song is searched, a MySQL query saves the song's name, artist and a link to buy it into a database table. But would thre any way to have some kind of hit counter that could increment every time a song is searched instead of creating duplicates? Or any other way I could get a most popular search?

Here is the query that saves the data if it helps:

Expand|Select|Wrap|Line Numbers
  1. //Most popular
  2. mysql_query("INSERT INTO MostPopular (song_name, artist, purchase_link)
  3. VALUES ('$title', '$artist', '$Buy')");
  4.  
May 6 '11 #1

✓ answered by JKing

Hi again,

If you are saving each search, you could use the COUNT() keyword along with GROUP BY to generate a sum of the searches for each song. Once again if you use ORDER BY and DESC you will have your results from most to least.

Here's an example:
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(song_name) as song_count, song_name, artist 
  2. FROM MostPopular 
  3. GROUP BY song_name 
  4. ORDER BY song_count DESC
  5.  
You could also modify this to find the most popular artists, most popular songs by a specific artist etc.

If at all possible you may want to store songs by their ID as opposed to their name.

The more data you have, the more queries you can produce. For example you may want to start storing timestamps with your searches. This allows you to pull stats by month, week, day or year.

5 2395
JKing
1,206 Expert 1GB
Hi again,

If you are saving each search, you could use the COUNT() keyword along with GROUP BY to generate a sum of the searches for each song. Once again if you use ORDER BY and DESC you will have your results from most to least.

Here's an example:
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(song_name) as song_count, song_name, artist 
  2. FROM MostPopular 
  3. GROUP BY song_name 
  4. ORDER BY song_count DESC
  5.  
You could also modify this to find the most popular artists, most popular songs by a specific artist etc.

If at all possible you may want to store songs by their ID as opposed to their name.

The more data you have, the more queries you can produce. For example you may want to start storing timestamps with your searches. This allows you to pull stats by month, week, day or year.
May 6 '11 #2
Okay, so with these timestamps, would it be posible to do a "top ten" kind of thing that could refresh every day?
May 8 '11 #3
I've tried it out and the order of each one works fine, but the purchase link doesn't. It comes up with "Notice: Undefined index: purchase_link". Is this to do with the grouping?
May 9 '11 #4
JKing
1,206 Expert 1GB
I don't think that has to do with grouping without seeing the code that goes along with the error I can't tell you too much else.

But yes with timestamps you could do a daily top ten.
May 9 '11 #5
It wasn't working because I overlooked actually selecting it in the query in the first place. All sorted now (y)
May 10 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tim Constantine | last post by:
I have a table "Subscriptions". Subscriptions contains the columns "ChannelID" & "MemberID". The "Channels" table contains a column called "Title" When someone is viewing a channel, I would...
3
by: D Denholm | last post by:
I am a Access newbie... Hopefully somebody can help me figure this out. I have a database that looks like: Asset Economic Minimum ----- ---------------- 10555 ...
33
by: Jacob Oost | last post by:
Should I get some more general books, like "advanced self-teaching," or can I start on specialized books like "Linux game programming?" Any book recommendations? -- ----- BEGIN GEEK CODE...
2
by: Loane Sharp | last post by:
Hi there I'm using VB.NET and Office Web Components to access a SQL Server 2005 Express database and draw pictures on the fly in my ASP.NET application. Using .ExportPicture to write the...
19
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have <a href="javascript:somefunction()"what ... ?...
8
by: | last post by:
The New York Times and many other online publications automatically generate "most popular article" lists that cover, say, the last 24 hours. I am looking for guidance and/or code on the best way...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
2
by: asdasd10 | last post by:
here what i wrote : <% path = Server.mappath("../db/ServerData.mdb") set con = Server.createobject("ADODB.Connection") con.open "driver={Microsoft Access Driver (*.mdb)};DBQ="&path set...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.