MySQL中用于批量更新的Php if语句
这是我的第一篇文章。切中要害 我试图使用一个php if语句在MySQL表中进行批量更新,但由于我对MySQL一无所知,所以无法连接到数据库并逐个更新 因此,基本上我尝试使用这个if语句,它在名称中表示Casio这个词,并避免所有prodcuts在名称中单独使用保加利亚字母。代码工作正常,我只是不知道如何为MySQL实现它。希望您能对如何开始提供帮助MySQL中用于批量更新的Php if语句,php,mysql,if-statement,Php,Mysql,If Statement,这是我的第一篇文章。切中要害 我试图使用一个php if语句在MySQL表中进行批量更新,但由于我对MySQL一无所知,所以无法连接到数据库并逐个更新 因此,基本上我尝试使用这个if语句,它在名称中表示Casio这个词,并避免所有prodcuts在名称中单独使用保加利亚字母。代码工作正常,我只是不知道如何为MySQL实现它。希望您能对如何开始提供帮助 <?php require("words.php"); $product = "CASIO EF-513D-5AV MTP
<?php
require("words.php");
$product = "CASIO EF-513D-5AV MTP Chronograph";
if (strstr($product,"CASIO",0)) {
/*Watches for men*/
if (strstr($product,$gs,0) || strstr($product,$edifice,0) || strstr($product,$mtp,0) || strstr($product,$mrw,0)) {
if ($product == substr($avoid[0],0) || $product == substr($avoid[1],0) || $product == substr($avoid[2],0)) {
echo $product;
}
elseif(strstr($product,$gs,0)) {
echo str_replace($gs,$gsW,$product);
}
elseif(strstr($product,$edifice,0)) {
echo str_replace($edifice,$edificeW,$product);
}
elseif(strstr($product,$mtp,0)) {
echo str_replace($mtp,$mtpW,$product);
}
elseif(strstr($product,$mrw,0)) {
echo str_replace($mrw,$mrwW,$product);
}
}
}
/*Watches for women*/
elseif (condition) {
# code...
}
else{
}
?>
我只是不知道如果你看到
$avoid
如何告诉代码,不要对这些名称做任何事情,但对于其余的,请添加我指定的任何东西,对原始的$product字符串进行备份
<?php
$originalProduct = $product;
// Then your changes are to be made here
// Having finished modifying
$connection = mysqli_connect("localhost", "root", "", "database", 3306);
if($connection->connect_error)
{
// error occured while trying to connect to the database
}
else
{
$query = $connection->query("UPDATE `tablename` SET productName = '$product' WHERE productName = '$originalProduct' LIMIT 1;");
if($query)
{
// Successfully modified record
}
else
{
// error occured while trying to modify
}
}
?>
我想我找到了自己问题的答案
我可以用几个
$sql = "UPDATE product_description SET name = REPLACE(name, 'EDIFICE', 'Мъжки часовник EDIFICE');";
我只是不确定使用几个替换语句是否是一个好主意,我认为您只需要使用合适的WHERE
子句来限制SELECT
。
其中名称与“%Мъжжжжжааааа%”不相似,名称与“%Сааааааааа
您可以在PHP中按照以下行构造where
子句…
$where=“name不象“%”。内爆(“%”和name不象“%”,$avoid)。%%“
HTH所有这些变量的值是什么?你的更新查询在哪里?我会将它们添加到帖子中。这个想法是为了只为前端更新所有变量,但我遇到了一些问题,很抱歉,但是你让我在这里迷路了,我有点看不到这段代码如何帮助我查找“卡西欧”这个词“然后开始改变东西,基本上我需要找到卡西欧这个词,如果它找到了,它就开始寻找单词来避免$avoid=array(“Мъжжжжжжжжжжжжжжжжжжж;如果发现这一点,则将其更改为$gsW=“Мъжжжжжжжжжжжжж;正如我所说的,我对MySQL不太了解,但你能更详细地解释一下吗
<?php
$originalProduct = $product;
// Then your changes are to be made here
// Having finished modifying
$connection = mysqli_connect("localhost", "root", "", "database", 3306);
if($connection->connect_error)
{
// error occured while trying to connect to the database
}
else
{
$query = $connection->query("UPDATE `tablename` SET productName = '$product' WHERE productName = '$originalProduct' LIMIT 1;");
if($query)
{
// Successfully modified record
}
else
{
// error occured while trying to modify
}
}
?>
$sql = "UPDATE product_description SET name = REPLACE(name, 'EDIFICE', 'Мъжки часовник EDIFICE');";