我希望使用变量名$ newmass(常量数字)下的新值添加列mass_reach中数据库中的当前值。我在下面创建了一个双桶循环来提取当前值,然后添加它并在第二个循环中更新值,但似乎无法实现此目的。
if(isset($_POST['mass_reach'])){
$massreach = $_POST['mass_reach'];
foreach ($massreach as $massreach_id) {
$query4 = "SELECT mass_reach FROM coaches WHERE id='{$massreach_id}'";
$result4 = mysqli_query($con, $query4);
$query2 = "UPDATE coaches SET mass_reach='{$newmass}'+'{$result4}' WHERE id='{$massreach_id}'";
$result = mysqli_query($con, $query2);
}
}
我收到错误:我收到错误:可捕获的致命错误: mysqli_result类的对象无法在行中转换为字符串 8即
$query2 = "UPDATE coaches SET mass_reach='{$mass}'+'{$result4}' WHERE id='{$massreach_id}'";
答案 0 :(得分:0)
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);}
foreach ($mass_reach as $string) {
$c_id = get_string_between($string,"[","]");
$c_mass = get_string_between($string,"(",")");
$query2 = "UPDATE coaches SET mass_reach='{$mass}' + '{$c_mass}' WHERE id='{$c_id}'";
$result2 = mysqli_query($con, $query2);
}