I have a database that looks like this:
I need to delete entries like the 2nd to the 7th, I would only want one of those. They are all the same if the movie_id
, question_id
and value are the same.
I am currently doing the following, and it works until it times out but it times out after only a thousand or so entries, as you can tell by the ID column, there are over 50,000 entries.
$top_index = count($all_movies)-1;$top = $all_movies[$top_index];
$max = $top->id;
for($i = 25200; $i<$max-1;$i++){
for($j = 0; $j<$max-1;$j++){
if($i != $j){
if($all_movies[$i]->movie_id == $all_movies[$j]->movie_id){
if($all_movies[$i]->question_id == $all_movies[$j]->question_id){
if($all_movies[$i]->value == $all_movies[$j]->value){
echo 'Need to remove '. $all_movies[$j]->id.':<br> Movie Id:'.$all_movies[$i]->movie_id.' Question ID: '.$all_movies[$i]->question_id.' Value: '.$all_movies[$i]->value.'<br>';
echo 'Matched with: <br>'. $all_movies[$i]->id.': Movie Id:'.$all_movies[$j]->movie_id.' Question ID: '.$all_movies[$j]->question_id.' Value: '.$all_movies[$j]->value.'<br>';
$delete = $post2->movie_value_delete($all_movies[$j]->id);
echo 'Deleted: '.$all_movies[$j]->id.'<br><br>';
}
}
}
}
}
}