Jump to content

Recommended Posts

I have a query:

<?php
$sqlRowCount = "SELECT * FROM vote, songs WHERE vote.songID=songs.songID AND songs.genre IN ($genres) AND vote.date > NOW()-INTERVAL $time DAY";  
$resultRowCount = mysql_query($sqlRowCount) or die (mysql_error()); 
$numrows = mysql_num_rows($resultRowCount); 

 

If I put in 1 for $time and in my vote table I only have a maximum of 4 entries that have been voted on in the past 24 hours (date is equal to or greater than Jan. 7 or later), shouldn't I only get a maxiumum of 4 results from this query?

 

Right now its returning 6 results.  Does anyone know how this can be?

 

I really don't have any idea?

 

Did I do the "vote.date > NOW()-INTERVAL $time DAY" correctly?

 

Link to comment
https://forums.phpfreaks.com/topic/140009-solved-help-with-time-interval-in-query/
Share on other sites

I have this to validate it:

<?php
if(empty($time) || !is_numeric($time) || $time>365){
  $time = 30;
}

 

but I don't think I actually set it as any type....are you supposed to set the variables type?  I don't think I know how to do that in php...

 

ok this is the weirdest thing.....and you might not believe me, but it really happened....

 

the records that were within 24 hours actually ran out....they were at jan 6....at like 9 something am....

its 10 something here now....

anyway...I wasn't getting any hits for 24 hours...and I wondered why....so I found that out....

 

anyway...I changed the time on them to 11 am....and now it works good for time = 1.

 

I have 4 records that were within the last 24 hours, and now I only get 4 records....

 

but I tried putting in time = 2...and in the database, there are still only those 4 records that are within 2 days.....but its giving me 7 results.....

 

so now, 1 day works but 2 days doesn't work!

 

I tried putting in your DATE_SUB(NOW(), INTERVAL $time DAY)

 

I get the exact same results as with the NOW()-INTERVAL $time DAY

 

man....I am really confused here....

 

 

 

2 days should return more results...no? Why not print out the TIME in your while loop after returning the data and verify that they are not within the 2-day mark. I bet they are.

ok I'm an idiot......

 

I was looking at the phpadmin view at the table...and I didn't realize there was a page 2 with 3 more results!

 

it was working......I can't believe you knew that was probably the problem!

 

thanks guys....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.