PHP中使用多个条件的Mysql删除查询

发布于 2024-12-13 20:04:21 字数 221 浏览 5 评论 0原文

我想从表(PHP + Mysql)中删除数据,有三个条件。我尝试了“AND”和“,”,但不起作用。

mysql_query("DELETE FROM `posts-meta` WHERE `post_id` = '$postid' AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'")

有什么办法吗?

I want to delete data from table (PHP + Mysql), with three conditions. I tried both 'AND' and ',' but don't work.

mysql_query("DELETE FROM `posts-meta` WHERE `post_id` = '$postid' AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'")

Is there any way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福丶如此 2024-12-20 20:04:21

如果您正在寻找一个查询,该查询将删除与所有三个条件匹配的结果,那么您的查询是准确的:

DELETE FROM `posts-meta` WHERE `post_id` = '$postid' AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'

如果您要删除与任一条件匹配的所有结果,您应该去与 OR:

DELETE FROM `posts-meta` WHERE `post_id` = '$postid' OR `meta_name` = 'post_tag' OR `meta_value` = '$tag'")

希望我不会通过用这些常识重新陈述明显的内容来冒犯您,尽管您的问题确实缺少上下文,但我不知道您到底想要完成什么,为什么它不起作用,。 ..

If you're looking for a query that'll delete the results that match to all three of your conditions, you're query is accurate:

DELETE FROM `posts-meta` WHERE `post_id` = '$postid' AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'

If you're looking to delete all results matching to either one of your conditions, you should go with OR:

DELETE FROM `posts-meta` WHERE `post_id` = '$postid' OR `meta_name` = 'post_tag' OR `meta_value` = '$tag'")

Hope I don't offend you by re-stating the obvious with this common knowledge, though your question is really missing context, I have no idea what exactly you're trying to accomplish, why it doesn't work, ...

硬不硬你别怂 2024-12-20 20:04:21

不要用这种丑陋的方式运行查询,而是将所有代码塞进一行,始终使其合理,并始终添加一些错误检查

如果您有以这种方式运行查询的习惯,至少

$sql = "DELETE FROM `posts-meta` WHERE `post_id` = '$postid' 
        AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'";
mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);

您会收到有关错误的通知,并且不会浪费您和其他人的时间。

instead of this ugly way of running queries, stuffing all your code in just one line, always make it sensible, and always add some error checking.

If you had a habit of running queries at least this way

$sql = "DELETE FROM `posts-meta` WHERE `post_id` = '$postid' 
        AND `meta_name` = 'post_tag' AND `meta_value` = '$tag'";
mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);

you'd been notified of the error and wasted no time of yours and other people.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文