FalsAlarm Posted November 24, 2017 Share Posted November 24, 2017 Hello everyone, I have a database of information and links to images(photos) on my servers filesystem. I'd like to write a script that reads from the database and updates my webpage automatically. In my database I have a timestamp along with a title, description and a link to a relevant image(photo). I'd like to somehow read from the database and only show records that are past a given time. My database is mySQL and the timestamp in the database is stored as a mySQL datetime datatype. 1. How to I convert the mySQL datetime to a php date so that I can compare the current php time with the mySQL datetime and then make a decision to post records only those records that are before the current time plus a random time between 5 and 15 minutes. Although I've been programming with php for awhile, I still can't quite wrap my mind around how the php code or sql query would look to perform this task. My goal is to read from the database and post only those records that have a datetime that is anywhere from 5 to 15 minutes later than php's current time on the server. I actually have a php form that I use to update the database with new records(title,description,image(photo) link). My goal is to have the website auto update itself based on the records that I have scheduled to be posted based on 5 to 15 minutes from my php current time. I usually write object oriented php, any help on some idea's about how this should/could be done would be appreciated. please and thanks, FalsAlarm, Quote Link to comment Share on other sites More sharing options...
FalsAlarm Posted November 24, 2017 Author Share Posted November 24, 2017 It just occured to me that when I insert the record(s) into the database, at that time, I should be creating the datetime to be stored and I should be inputting a random time. So I guess i'm already partly the way there. Any idea's on how I could check the last records datetime in the database and generate a random time between the current time and 5 to 15 minutes later so that I can put that code into the form pages code would help as well. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 24, 2017 Share Posted November 24, 2017 You do not need any php time functions, mysql has its own. The NOW() function will give you the current time. Assuming your timestamp column is called "imagetime" ... WHERE imagetime BETWEEN NOW() + INTERVAL 5 MINUTE AND NOW() + INTERVAL 15 MINUTE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.