Solved

using php return data from Mysql where datetime column is 30 mins or older

Posted on 2013-06-14
6
472 Views
Last Modified: 2013-06-14
Hi

I'm using PHP to look into my mySQL data and return some for sale items. I want non paying members to NOT see new additions so there is a 30 minute delay for them.

How can I create that in the PHP code please?

an example datetime entry in my datebase is : 2013-06-04 12:34:56

so, a user visiting at 2013-06-04 12:44:56 should not see it yet a visitor coming after 30 mins of the datetime 2013-06-04 14:34:56 can see it.

Neil
0
Comment
Question by:Neil Thompson
  • 3
  • 2
6 Comments
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39247216
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39247221
A sample query might go something like this...
$then = date('c', strtotime('now - 30 minutes'));
$sql = "SELECT ... WHERE addition_time <= '$then' ORDER BY...";
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 39247315
This can be done in MySQL like so
SELECT * FROM yourtable WHERE entrytime < NOW() - INTERVAL 30 MINUTE;

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 39247519
Many thanks these 2 tips worked a treat
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39247537
Thanks for the points - good question! ~Ray

PS: Take note of the possibilities of time differences between the client and the server, and also the possibility that the MySQL server may have time settings independent of the PHP server.
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39247718
and also the possibility that the MySQL server may have time settings independent of the PHP server

This is relevant only if the date/time information is originating from the PHP Server.

If the records are being updated with a NOW() or CURRENT_TIMESTAMP action then MySQL server time would be the definitive source and the MySQL approach would be the correct way to search for records.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL Challenge... 7 37
Echo Multiple values from multiple records 19 45
Returning errors to display in a dialog box - Ajax, Json, Php 16 34
Reference key in foreach loop 4 22
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question