duansen6750 2011-07-19 09:49
浏览 21
已采纳

如何在mysql php中使用IN OPERATOR删除所有行

i am having problem in understanding the behaviour of this programme below is simple code to delete the email address using IN operator

$emails = $_POST['ids'];
    $sql = "DELETE FROM newsletter where email ";
    $condition = sprintf('IN ("%s")',implode(' "," ',$_POST['ids']));
    $sql = $sql.$condition;
    include '../includes/db.php';
    $r = mysql_query($sql);

    echo $sql;

it only deletes one email id and returns true . how can i make it run in a way it deletes all the emails .

below is the query constructed using the above code.

DELETE FROM newsletter where email IN ("adfadsf@gmail.com "," asdfasfasf@gmail.com "," kjhkhsd@assdfsdf.sdfsf "," shit@gshit.com "," someother@gmail.com")

is it wrong way of deleteing ?

  • 写回答

4条回答 默认 最新

  • duanmen2189 2011-07-19 09:51
    关注

    Instead of:

    $condition = sprintf('IN ("%s")',implode(' "," ',$_POST['ids']));
    

    do:

    $condition = sprintf('IN ("%s")',implode('", "',$_POST['ids']));
    

    IN operator matches contents of the field with the values exactly. Spaces at the beginnings and ends of values might have cause your problems.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?