Jump to content

Delete after X hours


Joshua F

Recommended Posts

I am trying to make a function that is customizable to delete a query from a database.

 

Here's the function.

function checkHashs($hours) {
        if($getHashs = mysql_query('SELECT * FROM `hash_codes`')) {
          $dateQ = mysql_query('SELECT MAX(addedon) AS lastVoteDate FROM `hash_codes`') or die(mysql_error());
          $getDate = mysql_fetch_assoc($dateQ);
          $diffrence = time() - strtotime($getDate['lastVoteDate']);
		  echo $diffrence / 60 / 60;
          if (($diffrence / 60 / 60) >= $hours) {
			mysql_query('DELETE FROM `hash_codes` WHERE `addedon` = '. ($diffrence / 60 / 60) >= $hours .'') or die(mysql_error());
          }
}
}

 

And I am trying to call it by

checkHashs(24);

 

What I am trying to do is make it so when that function is ran it will delete all oh the guerys that have the `addedon` row over X hours(24 hours in this case).

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/222887-delete-after-x-hours/
Share on other sites

Your delete query is wrong...check and recheck...the construct is wrong..

 

 

I am trying to make a function that is customizable to delete a query from a database.

 

Here's the function.

function checkHashs($hours) {
        if($getHashs = mysql_query('SELECT * FROM `hash_codes`')) {
          $dateQ = mysql_query('SELECT MAX(addedon) AS lastVoteDate FROM `hash_codes`') or die(mysql_error());
          $getDate = mysql_fetch_assoc($dateQ);
          $diffrence = time() - strtotime($getDate['lastVoteDate']);
		  echo $diffrence / 60 / 60;
          if (($diffrence / 60 / 60) >= $hours) {
			mysql_query('DELETE FROM `hash_codes` WHERE `addedon` = '. ($diffrence / 60 / 60) >= $hours .'') or die(mysql_error());
          }
}
}

 

And I am trying to call it by

checkHashs(24);

 

What I am trying to do is make it so when that function is ran it will delete all oh the guerys that have the `addedon` row over X hours(24 hours in this case).

 

Any ideas?

Your delete query is wrong...check and recheck...the construct is wrong..

 

 

I am trying to make a function that is customizable to delete a query from a database.

 

Here's the function.

function checkHashs($hours) {
        if($getHashs = mysql_query('SELECT * FROM `hash_codes`')) {
          $dateQ = mysql_query('SELECT MAX(addedon) AS lastVoteDate FROM `hash_codes`') or die(mysql_error());
          $getDate = mysql_fetch_assoc($dateQ);
          $diffrence = time() - strtotime($getDate['lastVoteDate']);
		  echo $diffrence / 60 / 60;
          if (($diffrence / 60 / 60) >= $hours) {
			mysql_query('DELETE FROM `hash_codes` WHERE `addedon` = '. ($diffrence / 60 / 60) >= $hours .'') or die(mysql_error());
          }
}
}

 

And I am trying to call it by

checkHashs(24);

 

What I am trying to do is make it so when that function is ran it will delete all oh the guerys that have the `addedon` row over X hours(24 hours in this case).

 

Any ideas?

?????????

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.