I have a table like so:
And I would like to delete all duplicated values of 'Ognjen' and 'Nikola' and to save only those two, without their duplicates. I tried like so:
public function findDuplicate($tabela){
$query = "SELECT `user_facebook_id` FROM $tabela GROUP BY `user_facebook_id` HAVING count(*) > 1";
$rez = $this->db->query($query, 3);
if($rez){
return $rez;
}else{
return false;
}
}
$duplicateResult=$settings->findDuplicate($tabela);
if($duplicateResult){
echo '<div class="alert alert-warning">
<strong>Warning!</strong> We can see that some of users you inserted already exists in database, so we are authorized to delete them.
</div>
';
foreach($duplicateResult as $result){
$to=$result['user_facebook_id'];
$mysqli1 = new mysqli('localhost','servis_user','QrbRJQK7r52nFpx2','servis_racunara');
$q="DELETE FROM $tabela WHERE `user_facebook_id`=$to";
$rez=$mysqli->query($q);
var_dump($rez);
}
}
But all this did was to delete everything from my table. So there was no 'Ognjen' nor 'Nikola' anymore. Please help, I'm stuck with this.