winday 发表于 2004-8-14 22:16:07

数据库整理的问题

检查2张表,如果LOGIN里没这个ACCOUNT_ID,那就删除CHAR表中删除LOGIN里没的这个ACCOUNT_ID有关数据,能显示出要删除的数据,但是删8了……为虾米~高手帮忙看看,程序如下~
$connect=mysql_connect("192.168.0.1","root","") or die(mysql_error());
mysql_select_db("rakbak");
echo "char table delete:";
$k=0;
$query = "select * from `char` ";
$result = mysql_query($query);
while ($r=mysql_fetch_array($result)){
$aid = $r['account_id'];
$cid=$r['char_id'];
$name=$r['name'];
$query = "select * from login where account_id=$aid";
$res = mysql_query($query);
$total_count = mysql_affected_rows();
if($total_count<1) {
$k++;
$query = "delete from char where account_id=$aid";
$res0 = mysql_query($query);
}
}
echo $k;

jiangtao9999 发表于 2004-8-14 23:04:14

你把所有 query 语句全 echo 出来,看看对不对~~~
页: [1]
查看完整版本: 数据库整理的问题