Compare and delete rows from a table
Posted: Sat Sep 20, 2003 1:25 pm
I have a table with a lot of lines. Some of the lines are twice. All I want to do is to compare and erase some of them and to keep only one.
I use the that but my table was erased completly.[mod_edit: added
I use the that but my table was erased completly.
Code: Select all
<?php
mysql_connect('localhost','root','');
mysql_select_db('site');
$query="select * from funnysms where sms_cat='doublemeaning'";
$result=mysql_query($query);
$query2="select * from funnysms where sms_cat='doublemeaning'";
$result2=mysql_query($query2);
while ($row=mysql_fetch_array($result)){
while ($row2=mysql_fetch_array($result2)){
if ($row2['sms_desc']==$row['sms_desc']){
$query3="delete from funnysms where ".$row2['sms_desc']."=".$row['sms_desc'];
mysql_query($query3);
}
}
mysql_data_seek($result2,0);
}
?>Code: Select all
tags][/size]
So where I'm wrong? Can I do it in other way to do what I want?