Solved

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

Posted on 2013-06-14
6
465 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 54

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 54

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

778 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