Thanks alot you guys.
Here is my entire situation:
On my site I have been allowing song uploads and people rate and review them. The ratings are stored in mysql as a float column. (4.05 3.99, ..). I need to design a daily script to run as a cron job, but first, I am trying to design a script that will go back through the ratings thus far and find the Top 3 rated songs per day. (Sorry, xblue, I didnt realize that I wanted to do that in the other thread until I had marked it resolved, your solution was great).
Tell me if you think this is a good idea, I designed a table called daily_winners and I am trying to calculate the top 3 songs per day in the songs table and insert them into the daily_winners table. Heres what I have that was very close:
$get = "SELECT songid, bandid, MAX(srating) as srating, sdate, DATE_FORMAT(sdate, '%c/%e/%Y') AS sdate2, stitle FROM songs GROUP BY sdate2 ORDER BY sdate DESC";
$chk2 = mysql_query($get, $conn);
if(mysql_num_rows($chk2)) {
while ($row2 = mysql_fetch_array ($chk2)) {
$songid = addslashes($row2['songid']);
$bandid = addslashes($row2['bandid']);
$srating = addslashes($row2['srating']);
$sdate = addslashes($row2['sdate']);
$stitle = addslashes($row2['stitle']);
echo "$stitle<br>";
$get3 = "INSERT INTO daily_winners SET songid='$songid', bandid='$bandid', srating='$srating', sdate='$sdate', stitle='$stitle'";
$chk3 = mysql_query($get3, $conn) or die(mysql_error());
}}
Thanks to xblue's help I got that far but now I need to somehow adjust it to pull the top 3 results per day instead of just the first.
Is there a way that I can just store the first date (11-15-04) as a variable and increment it by one day in a loop?
$sdate = 11-15-04;
while{...
$get = "SELECT songid, bandid, srating, DATE_FORMAT(sdate, '%c/%e/%Y') AS sdate, stitle FROM songs WHERE sdate='$sdate' ORDER BY srating DESC LIMIT 3";
INSERT INTO...
$sdate = $sdate + 1 day;
}
It seems like that would work but I dont know how to increment $sdate by a day.