Hi Dave,
Yes it is a bit of a mess!
The table is automatically updated every day.
I have six months of messed up data !!!
Actually I have neglected to check it and I have to wade through it deleting and changing data.
I have already spent a few hours doing this - and thought it best to try and write a script to do it.
( I have got to day 170, and I need to go up 380 ! )
This is what I have been doing "manually":
First delete duplicates that appear by using the sequential mprod_id number:
$sql_adm = "DELETE FROM main WHERE mday_no = '169' AND mprod_id > '407148' ";
$result_adm = mysql_query($sql_adm) or die("could not DELETE FROM main ". mysql_error());
Then second correct the time stamp that was wriiten as zero for the next day:
$sql_adm = "UPDATE main SET m_date = '1276948800' WHERE mday_no = '170' ";
$result_adm = mysql_query($sql_adm) or die("could not DELETE FROM main ". mysql_error());
Finally third, I manually delete about five records which have characters in their id munber field
Well as you know - third is now donealt with as I have converted that field to int(10) so now those records have zero in them
Those three operations fix ONLY one day, so I move onto the next day by locating the next mprod_id where the day number changes.
(ın this cae it changes from 169 to 170 )
As there about 1700 entries a day - I look at the database to find the number ,then manually update my script, upload it to my server and rerun it. For each day.
Very tedious and I now see it will take me 10 - 12 hours to complete.
The main index is on the auto-insert field named "mprod_id"
That is what I use to find positions in the table.
I am going to work on a copy of the table - I'll do that now 🙂
Now I just realized that my loop can be a simple while loop ( I think )
ALSO,
I think I can find the last "Mark for Deletion" row by SELECTING and LIMITING
Like this:
$the_day = 171;
$the_date = 1276948800;
$the_row_no = 410631;
While ($the_day < 381 ) {
$row = "UPDATE main SET mrecurr = 'D' WHERE mday_no = '$the_day' AND mid = '0' ";
$result = mysql_query($row) or die("could not MARK FOR DELETION - non-numeric". mysql_error());
// Now find the last deleted item
$deleted = "SELECT * FROM `main` WHERE `mday_no` = '$the_day' AND mrecurr = 'D' ORDER BY mprod_id DESC limit 1"; ";
$result = mysql_query($deleted) or die("could not FIND DELETIONS". mysql_error());
$row = mysql_fetch_assoc($result);
$new_row_no = = $row['mprod_id'];
$row = "UPDATE main SET mrecurr = 'D' WHERE mday_no = '$the_day' AND mprod_id > '$the_row_n' ";
$result = mysql_query($row) or die("could not MARK FOR DELETION - duplicates". mysql_error());
$row = "UPDATE main SET m_date = '$the_date' WHERE mday_no = '$the_day' ";
$result = mysql_query($row) or die("could not UPDATE timestamp". mysql_error());
$the_day = $the_day+1;
$the_date = $the_date+86400;
$the_row_no = $new_row_no;
} // End While
What do you think ?
Does it look like it will do what I have been doing manually ?
I am not sure about the DESC with the LİMİT 1, will that give me the last row, i.e. the one with the highest mprod_id that has just been marked for deletion ?
Thanks.