int mysql_affected_rows ( [resource link_identifier])
mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated with link_identifier. If the link identifier isn't specified, the last link opened by mysql_connect() is assumed. mysql_affected_rows() 返回使用link_identifier进行的最后一次Insert, UPDATE或者DELETE查询受影响的行数。如果没有指定link identifier参数,那么默认是最后一个被mysql_connect()打开的连接。这样以来问题就简单了:if(mysql_affected_rows()>0)
{
    //有被删除的记录
}
else
{
    //没有被删除的记录
}

解决方案 »

  1.   

    $sql="delete from test where id='$rand'";
    $rs=mysql_query($sql) or die(mysql_error());
    if($rs)  echo "ok";
    else echo "no";不要把sql语句与查询返回值用同一个变量
      

  2.   

    用$query的结果判断SQL语句是否被执行。
    用mysql_affected_rows() 判断被执行,受影响的记录有几条如果大于0就说明检索到,或修改数据库中的信息,否则SQL语句没有找到相关记录。