Hi and thanks,
I used two tables in hopes that it would be faster to sort through a weekly tableof 300,000 entries than querying a monthly table with over a million entries determining which are less than 7 days old.
Can you please explain the timestamp as an index idea to me?
I tried this at one point:
$getrevs = "SELECT songid FROM weekly_plays WHERE bandid='$bandid' AND songid='$songid' AND playdate=now()";
$rs5 = mysql_query($getrevs, $conn);
if(mysql_num_rows($rs5) > 0){
$sql8 = "UPDATE weekly_plays SET score=score+1 WHERE bandid='$bandid' AND songid='$songid' AND playdate=now()";
$result8 = mysql_query($sql8) or die(mysql_error());
}
else{
$sql8 = "INSERT INTO weekly_plays SET songid='$songid', playdate=now(), bandid = '$bandid', score=1";
$result8 = mysql_query($sql8) or die(mysql_error());
}
$getrevs = "SELECT songid FROM monthly_plays WHERE bandid='$bandid' AND songid='$songid' AND playdate=now()";
$rs5 = mysql_query($getrevs, $conn);
if(mysql_num_rows($rs5) > 0){
$sql8 = "UPDATE monthly_plays SET score=score+1 WHERE bandid='$bandid' AND songid='$songid' AND playdate=now()";
$result8 = mysql_query($sql8) or die(mysql_error());
}
else{
$sql8 = "INSERT INTO monthly_plays SET songid='$songid', playdate=now(), bandid = '$bandid', score=1";
$result8 = mysql_query($sql8) or die(mysql_error());
Where it would check to see if an entry for that date, songid, and bandid exists in the table and if so, add one to that value. I thought it would help cut down on the number of entries but it was making the query to INSERT too slow.