To start with, I am a complete beginner when it comes to PHP.

I am working on a blog page that uses PHP and MySQL. The blog is stored in MySQL with the following headings: blog_id, blog_title, blog_author, blog_text, blog_posix_start, blog_image, and blow_allow.

"blog_posix_start" takes the date and time entered and turns it into a Unix timecode. What I want to do is have the webpage blog.php check "blog_posix_start" against today's date and only show blog posts that occur before today's date (ones entered for future dates wouldn't be visible).

Can anyone help me figure out what the PHP code to do something like that would look like? Specifically, I'm looking for sample code so I can understand what this would look like. Thank you in advance!

    If it's in the database it would be better to look there: save time retrieving blog posts only to skip them because they're too new.

    Since you're storing the date as an integer (blog_posix_start) instead of a date, then to get any useful date arithmetic out of it you'll need to convert it back into a date to make the comparison (Unix timestamps don't know of these "dates" of which you speak). I'll have to look up the MySQL manual to see how it's done there. Uh, FROM_UNIXTIME(blog_posix_start)<CURDATE() or maybe blog_posix_start<UNIX_TIMESTAMP(CURDATE()). Maybe. CURDATE() returns a string or an integer instead of an actual date type, but it looks like UNIX_TIMESTAMP() will take a string, so I guess it works out.

    (Actually, your requirements only mention posts date "before today" and "future dates", but don't say what to do with posts dated today).

      Write a Reply...