473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need mini-code review

$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement > ' .
'nnet_produkt_placement + \'' . date("Y-m-d H:i:s", time() +
$maxCartTime) . '\'';

This is supposed to delete all rows in nnet_produkt_bestilling whose value
in the field nnet_produkt_placement is more than $maxCartTime seconds old
($maxCartTime, in this case = 86400 seconds, or 24 hours). I am unsure if
this is the correct syntax using mySQL to do such an action upon a DATETIME
field column datatype, so if someone could look that over and see how far
out of the ballpark I really am I'd appreciate it.

Thanx
Phil
Jul 17 '05 #1
5 2135
On Tue, 30 Sep 2003 00:32:31 -0400, Phil Powell wrote:
$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement > ' .
'nnet_produkt_placement + \'' . date("Y-m-d H:i:s", time() +
$maxCartTime) . '\'';


The easiest way is to use MySQL's built in functions:

$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement < DATE_SUB(NOW(), INTERVAL 24 HOURS)';
Cheers,
Andy
Jul 17 '05 #2
Thanx but don't you mean > DATE_SUB(NOW(), INTERVAL 24 HOURS)?

Phil

"Andy Jeffries" <ne**@andyjeffries.remove.co.uk> wrote in message
news:pa****************************@andyjeffries.r emove.co.uk...
On Tue, 30 Sep 2003 00:32:31 -0400, Phil Powell wrote:
$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement > ' .
'nnet_produkt_placement + \'' . date("Y-m-d H:i:s", time() +
$maxCartTime) . '\'';
The easiest way is to use MySQL's built in functions:

$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement < DATE_SUB(NOW(), INTERVAL 24

HOURS)';

Cheers,
Andy

Jul 17 '05 #3
On Tue, 30 Sep 2003 07:19:36 -0400, Phil Powell wrote:
Thanx but don't you mean > DATE_SUB(NOW(), INTERVAL 24 HOURS)?


No, you want to delete all baskets older than a certain time, e.g. 24
hours old.

So, say you have the following table:

+--+-------------------+
|ID|DateCreated |
+--+-------------------+
| 1|2003-09-28 00:00:00|
| 2|2003-09-30 12:31:00|
+--+-------------------+

DATE_SUB(NOW(), INTERVAL 24 HOURS) will equate to:

NOW(): 2003-09-30 12:41:56
SUB : 2003-09-29 12:41:56

As you can see from the table, you want to delete basket ID 1, but not ID
2 (as it's was only created 10 minutes ago).

So the question you want to ask is 2003-09-28 (ID1:DateCreated) less than or greater than
2003-09-29 (SUB)?

Of course it's less than, therefore your WHILE criteria should be less
than.

If you use greater than you will be constantly deleting baskets that are
less than 24 hours old and keeping all your old ones.

Does that make more sense now or have I rambled on and confused the issue?

Cheers,
Andy

Jul 17 '05 #4
My date-math skills are absolutely nonexistent since it's pure logic and I
don't have that, so everything you said made no sense until you used an
example. I still don't get it between "<" and ">" but in this case I'll
just take your word for it.

Unfortunately, it doesn't work :( Produces a mysql_error near 'HOURS)'

I honestly have found nothing on www.mysql.com or anywhere else that can
address this problem. All I simply want to do is to delete rows from a
table where nnet_produkt_record_entered is more than 24 hours old. I
thought this would do it but it produces a mysql_error near 'HOURS)':

$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement < DATE_SUB(NOW(), INTERVAL 24
HOURS)';

Any ideas, sorry I'm fresh out as usual.

Thanx
Phil

"Andy Jeffries" <ne**@andyjeffries.remove.co.uk> wrote in message
news:pa****************************@andyjeffries.r emove.co.uk...
On Tue, 30 Sep 2003 07:19:36 -0400, Phil Powell wrote:
Thanx but don't you mean > DATE_SUB(NOW(), INTERVAL 24 HOURS)?
No, you want to delete all baskets older than a certain time, e.g. 24
hours old.

So, say you have the following table:

+--+-------------------+
|ID|DateCreated |
+--+-------------------+
| 1|2003-09-28 00:00:00|
| 2|2003-09-30 12:31:00|
+--+-------------------+

DATE_SUB(NOW(), INTERVAL 24 HOURS) will equate to:

NOW(): 2003-09-30 12:41:56
SUB : 2003-09-29 12:41:56

As you can see from the table, you want to delete basket ID 1, but not ID
2 (as it's was only created 10 minutes ago).

So the question you want to ask is 2003-09-28 (ID1:DateCreated) less than

or greater than 2003-09-29 (SUB)?

Of course it's less than, therefore your WHILE criteria should be less
than.

If you use greater than you will be constantly deleting baskets that are
less than 24 hours old and keeping all your old ones.

Does that make more sense now or have I rambled on and confused the issue?

Cheers,
Andy

Jul 17 '05 #5
Phil Powell wrote:
My date-math skills are absolutely nonexistent since it's pure logic and I
don't have that, so everything you said made no sense until you used an
example. I still don't get it between "<" and ">" but in this case I'll
just take your word for it.

Unfortunately, it doesn't work :( Produces a mysql_error near 'HOURS)'

I honestly have found nothing on www.mysql.com or anywhere else that can
address this problem. All I simply want to do is to delete rows from a
table where nnet_produkt_record_entered is more than 24 hours old. I
thought this would do it but it produces a mysql_error near 'HOURS)':

$sql = 'DELETE FROM nnet_produkt_bestilling ' .
'WHERE nnet_produkt_placement < DATE_SUB(NOW(), INTERVAL 24
HOURS)';

Any ideas, sorry I'm fresh out as usual.


Use 'HOUR' instead of 'HOURS'.

--
Seks, seksić, seksolatki... news:pl.soc.seks.moderowana
http://hyperreal.info { iWanToDie } WiNoNa ) (
http://szatanowskie-ladacznice.0-700.pl foReVeR( * )
Poznaj jej zwiewne kształty... http://www.opera.com 007
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fibvortex | last post by:
The Fibvortex is now offering Managed Mini Forex Accounts with NO Management Fee! Receive the same benefits as our regular managed account at a fraction of the price. You will designate the...
5
by: abhishekjha10 | last post by:
Hello everybody, I am trying to create a mini OS in C. Can you help me with some helpful links and sites. Thankyou. Abhishek Jha.
2
by: Daniel | last post by:
Hi , i was just wondering if it is possible to create a mini game in vb.net say for example like space invaders with a spacecraft coming across the top of the screen in a web form dropping...
0
by: Andrew Dalke | last post by:
Years ago I wrote the Sorting mini-howto, currently at http://www.amk.ca/python/howto/sorting/sorting.html I've had various people thank me for that, in person and through email. It's...
1
by: res7cxbi | last post by:
I'm not sure if you can even do this in c# but how can you get an app to do something like what Windows Media Player 10 does when you minimize it (the "Mini Player toolbar" mode)
3
by: alpa shah | last post by:
Hi, please suggest me Mini project topic in ASP language....
1
by: julian_m | last post by:
I'm just beggining to write some simple-small script which is gonna work as a mini chat. First aproach: File: comments.xml every time this file is accessed, I delete the first line (if number...
7
by: pangsans | last post by:
hai i wud like to do a mini project with two of my friends in c or c++.i jus cant decide on a suitable one.it wud n very very helpful if u guys cud suggest some topics
8
by: rshivaraman | last post by:
Hi : I have a TableA with around 10 columns with varchar and numeric datatypes It has 500 million records and its size is 999999999 KB. i believe it is kb i got this data after running...
1
by: =?Utf-8?B?VGhhZA==?= | last post by:
My Windows media player won't find the mini dvd - any help on how I can play these mini dvd's recorded on my camcorder in media player? I have media player 9. -- Thanks, Thad
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.