Jump to content

trying to show everything except for records created "today"


RyanSF07

Recommended Posts

Hi Guys,

 

I'm trying to display the content added to the database from the beginning of time until "yesterday" (or the day before). This is what I have so far and it returns a general error.

 

$sql = "SELECT video.id, title, description_text, category_text, level_text, user_name, 
DATE_FORMAT(date, '%M %D, %Y') as date FROM video, 
registered_users WHERE video.user_id = registered_users.id, 
(TO_DAYS(NOW()) - TO_DAYS(DATE_FORMAT(created,'%M %D %Y'))) < 2, ORDER BY id DESC";

 

Is there a better way to do this?

 

Thanks much for your help!

Ryan

Link to comment
Share on other sites

Thanks Ken,

 

The error is:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/5640/domains/eslvideo.com/html/ESL_WebTech_7/allquizzes.php on line 17

 

note: everything works perfectly until I add this condition:

(TO_DAYS(NOW()) - TO_DAYS(DATE_FORMAT(created,'%M %D %Y'))) < 2,

 

..which triggers the error.

 

I'm trying to form a condition that limits the data displayed to everything EXCEPT for what has been inserted "today."

Ryan

Link to comment
Share on other sites

Here is the error that is generated:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM video WHERE video.user_id = registered_users.id and DATE_SUB(CURDATE(),INTE' at line 1

 

I tried changing CURDATE to CURRENT_TIMESTAMP, but that just seemed to slow everything way down -- the page never loaded.

 

Thanks for you help,

Ryan

 

 

Link to comment
Share on other sites

$sql =SELECT video.id, title, description_text, category_text, level_text, user_name, FROM video

WHERE video.user_id = registered_users.id and DATE_SUB(CURDATE(),INTERVAL - 2 DAY) <= date ORDER BY id DESC;

 

Remove the comma that I colored.  Not sure if this would cause an error though :o

Link to comment
Share on other sites

Do you have two separate tables from which you are trying to cross-reference?

 

'video' and 'registered_users'?

 

That's the impression I got from the first post,  but in the latter ones you stopped using the 'registered_users' table. Maybe I'm wrong.

 

Link to comment
Share on other sites

Thanks Lytheum,

 

That helped. I think I'm almost there... but still getting an error.

 

With this:

$sql = "SELECT video.id, title, description_text, category_text, level_text, user_name, 
FROM video, registered_users WHERE video.user_id = registered_users.id and DATE_SUB(CURDATE(),INTERVAL - 1 DAY) <= date ORDER BY id DESC";

 

I get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM video, registered_users WHERE video.user_id = registered_users.id and DATE_' at line 2

 

And, if I leave the date part in, as in:

$sql = "SELECT video.id, title, description_text, category_text, level_text, user_name, 
DATE_FORMAT(date, '%M %D, %Y') as date FROM video, 
registered_users WHERE video.user_id = registered_users.id and DATE_SUB(CURDATE(),INTERVAL - 1 DAY) <= date ORDER BY id DESC";

 

then the page loads without any errors, yet nothing is selected/displayed from the database. ... it loads without error, properly formatted and everything, however no content is displayed  ???

 

Thanks again for all your help!

Ryan

Link to comment
Share on other sites

Maybe it would be smarter to make two separate sql statements. One for the registered_users table and another for the video table. Then you could generate a statement comparing the data from both. What is the structure of both of your tables, in this format:

 

->Database

-->Table

--->Column

--->Column2

--->Etc..

 

?

Link to comment
Share on other sites

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.