dongshan6870
dongshan6870
2017-01-19 12:57

从一个数组列中查找数组值的匹配项

已采纳

hello friends i have a code. i found matching of one array value in another array column and updated row with second array value. but i want to update status of first array record in mysql table with zero when no matches found.anybody knows please help. i will provide my code below

foreach ($result as $rel)
{
    foreach ($array as $arr)
    {
        if(strcmp(trim($rel['objId']),trim($arr['BCEID']))==0)
        {
            $name=$arr['FirstName'];
            $conditn=$rel['objId'];

            $sql1="UPDATE e_student SET Name = '$name' WHERE objId ='$conditn'";

            $result=$conn->query($sql1);
        }
    } 
}   
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongqiancui9194 dongqiancui9194 4年前
    foreach ($result as $rel)
    {
        $clk = 'no';
        foreach ($array as $arr)
        {
            if(strcmp(trim($rel['objId']),trim($arr['BCEID']))==0)
            {
                $clk = 'yes';
                $name=$arr['FirstName'];
                $conditn=$rel['objId'];
    
                $sql1="UPDATE e_student SET Name = '$name' WHERE objId ='$conditn'";
    
                $result=$conn->query($sql1);
            }
        } 
        if($clk=='no')
        {
            // write query here to set status 0
        }
    } 
    
    点赞 评论 复制链接分享