Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Delete entry after a week
Old 07-17-2008, 05:52 AM Delete entry after a week
Skilled Talker

Posts: 60
Trades: 0
Is it possible to delete an entry from a database that has been there for a set amount of time, say a week or a month? I thought that if the database has a timestamp entry and then I used something like:
PHP Code:
<?php
$con 
mysql_connect("hostname/server IP","username","password");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("databasename"$con);
mysql_query("DELETE FROM table_name WHERE time > 'date('dS F Y')+7'");
mysql_close($con);
?>
Thanks
thehappyappy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-17-2008, 10:12 AM Re: Delete entry after a week
Skilled Talker

Posts: 71
Trades: 0
Don't think your syntax will work.

But, this should work:

PHP Code:
<?php

$con 
mysql_connect("hostname/server IP","username","password");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("databasename"$con);
$sql mysql_query ("SELECT FROM table_name");
$row mysql_fetch_array ($sql);

if (
$row['timestamp'] <= strtotime ('-1week',time())) {
    
$delete mysql_query("DELETE FROM table_name WHERE id='".$row['id']."'");
}

mysql_close($con);

?>
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 07-17-2008, 11:14 AM Re: Delete entry after a week
Skilled Talker

Posts: 60
Trades: 0
brilliant thank you
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 07-18-2008, 03:48 AM Re: Delete entry after a week
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
OMG WTF, scan the table in a cycle and delete records obe by one?

delete from tablename where date_sub(now(), interval 1 week) > timefield

When will you guys start reading the manual?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 07-18-2008, 07:13 AM Re: Delete entry after a week
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
lol...

slightly off topic, but is it just me who wishes the MySQL manual was as easy to use as the PHP one? i can never find what i need on mysql

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 07-18-2008, 08:57 AM Re: Delete entry after a week
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Dan, that just because you are not looking at the right place.

If you are looking for functions, simply search for "time functions" or "string functions".
If you are looking about the syntax, look up the select, update or delete help pages.

But if you are looking about the different joins, it's true that it won't be covered by the manual, or very lightly.
And it's not the place to learn about the SQL syntax.
You have pages like http://technet.microsoft.com/en-us/m...chNet.10).aspx and http://www.sql-tutorial.net/SQL-JOIN.asp for that.

Once that you know how to structure the query, you know everything you need.
The rest is just optimisation (or almost).
But I won't start about set based programming. It's friday, for god sack...
3 more hours before a good fresh beer....
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-20-2008, 04:48 AM Re: Delete entry after a week
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
There is a nice mysql manual in chm format right in mysql website
http://downloads.mysql.com/docs/refman-5.1-en.chm
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Delete entry after a week
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64205 seconds with 12 queries