Joshua F Posted December 29, 2010 Share Posted December 29, 2010 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 More sharing options...
tobimichigan Posted December 29, 2010 Share Posted December 29, 2010 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? Link to comment https://forums.phpfreaks.com/topic/222887-delete-after-x-hours/#findComment-1152491 Share on other sites More sharing options...
Joshua F Posted December 29, 2010 Author Share Posted December 29, 2010 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? ????????? Link to comment https://forums.phpfreaks.com/topic/222887-delete-after-x-hours/#findComment-1152492 Share on other sites More sharing options...
tobimichigan Posted December 29, 2010 Share Posted December 29, 2010 break it up into 2 parts viz a viz: $del="del from3 where 4=5"; $qry=mysql_query($del); Link to comment https://forums.phpfreaks.com/topic/222887-delete-after-x-hours/#findComment-1152495 Share on other sites More sharing options...
tobimichigan Posted December 29, 2010 Share Posted December 29, 2010 $qry=mysql_query($del) or die mysql_error(); Link to comment https://forums.phpfreaks.com/topic/222887-delete-after-x-hours/#findComment-1152496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.