Jump to content

monika0021

Members
  • Posts

    3
  • Joined

  • Last visited

monika0021's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thanks a lot, but still no result.
  2. HelloI am trying to delete records from mysql database. Records should be removed after the chosen date. Unfortunately, it doesn't work. Instead of removing only outdated records, all records added today are deleted with warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 25 (- the line with the while loop)Here's the code: <?mysql_connect ("host", "user", "password") or die ("Cannot connect with MySQL"); mysql_select_db ("db") or die ("Cannot connect with database"); $query = "SELECT * FROM table WHERE year IS NOT NULL”; $result = mysql_query($query) or die (mysql_error()); while ($rekord = mysql_fetch_assoc ($result)) { $year = $rekord['year']; // varchar(4) field in db $month = $rekord['month']; //char(2) field in db $day = $rekord['day']; //char(2) field in db if ($year && $month && $day) { $day=$day+1; // day of deleting records $timestamp = strtotime($year."-".$month."-".$day); $kasuj=date("Y-m-d", $timestamp); if (date("Y-m-d")>=$kasuj) {$query = "DELETE FROM table WHERE CURDATE() >='".$kasuj."' AND year IS NOT NULL"; $wynik = mysql_query($query) or die (mysql_error()); print "Old recods removed"; } } }?>
×
×
  • Create New...