php - 如何在删除时编写此代码的快捷方式

标签 php mysql

我想为此代码编写快捷方式

例如,如果它包含数据库中的某些单词 my_table {id,my_words}

,我将删除许多条目
$sql= "delete from my_table where my_words like '%some1%' or my_words like '%some2%'";
mysql_query($sql) or die("query failed: $sql".mysql_error());

我有很多像 some3 , some4 , some5 ..etc 所以我不能重复 或 my_words 像 '%some2%'

很多时候,否则会很困难,而且代码又很长。 那么我怎样才能编写像使用数组或其他东西一样的快捷方式!

感谢帮助

最佳答案

$a = array('your','words',...);

foreach($a as $k=>$value{
$sql= "delete from my_table where my_words like '%$value%'";
mysql_query($sql) or die("query failed: $sql".mysql_error());
}

这次不要在 sql 语句中使用 OR,只需循环,因为您需要删除所有内容 - 只需对每个单词执行此操作即可。

关于php - 如何在删除时编写此代码的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379990/

相关文章:

php - 无效对象或资源 mysqli_stmt 错误

php - php中如何区分选择查询和非选择查询

mysql - 如何在一列中选择具有相同值但在另一列中彼此之间必须不同的行

php - 将一个应用程序连接到另一个应用程序的数据库时出错

php - 在 Woocommerce 中重命名多个订单状态

php - mysqli_query 在 If 语句中不起作用

php - 如何检查 URL 是否具有有效的公共(public) TLD?

mysql - 使用 InnoDb 时 UPDATE 语句是单独锁定表中的行还是完全锁定表中的行

mysql - 如何优化 MySQL 查询

php - Foreach 循环使用 php 获取记录中数组中的最后一项?