需要帮助将所有查询更改为面向部门

时间:2010-02-03 13:35:42

标签: php mysql

我正在像这样得到我的deptid

$deptid=$_SESSION['deptid'];

public function setSkillMatrix($data)
    {
        //return print_r($data,true);
        //$ot="";
        $deptid=$_SESSION['deptid'];
        if(!$data || !is_array($data)|| !sizeof($data)){throw new Exception("No data sent.".(is_object($data)?"y":"n"));}

        //throw new Exception(print_r($data,true));
        $effectedRows=0;
        $skills=$this->getSkills();
        array_shift($data);//get rid of the first row
        foreach($data as $row)
        {
            $userid=mysql_real_escape_string($row[0]);
            if(SHOW_VERTICAL){
                array_splice($row,0,4);
            }else{
                array_splice($row,0,3);
            }
            for($i=0;$i<sizeof($row);$i++)
            {
                if($row[$i]==""||$row[$i]=="Not Set")$row[$i]="NULL";
                else $row[$i]="'".mysql_real_escape_string($row[$i])."'";
                if($skills[$i]['isBranch']=="true")continue;
                $skillid=$skills[$i]['id'];
                $sql="SELECT * FROM `user_ratings` WHERE userid='{$userid}' AND skillid='{$skillid}' LIMIT 1";
                $result=mysql_query($sql);
                if(!$result){throw new Exception(mysql_error());}
                if(!mysql_num_rows($result))
                {
                    $sql="INSERT INTO `user_ratings` (userid,skillid,rating) VALUES('{$userid}','{$skillid}',NULL";
                    $result=mysql_query($sql);
                    if(!$result){throw new Exception(mysql_error());}
                }
                $sql="UPDATE `user_ratings` SET rating={$row[$i]} WHERE userid='{$userid}' AND skillid='{$skillid}";
                $result=mysql_query($sql);
                if(!$result){throw new Exception(mysql_error());}
                $effectedRows+=mysql_affected_rows();
                //if(mysql_affected_rows()){$ot.=$sql;}
            }
            //echo $userid." => ".implode(',',$row).'<br>';
        }
        if($effectedRows==0)
        {
            return "Database successfully updated although no changes were detected.";
        }else{
            return "Database successfully updated.";//.$effectedRows.$ot;
        }

    }//function

我需要将查询更改为部门...以便我可以更新特定部门的值......

1 个答案:

答案 0 :(得分:0)

PHP代码非常糟糕 - 并且无法为您的问题提供任何相关信息。

我们需要查看您的数据架构。

我希望您需要重新编写每个SELECT语句(假设当前正在捕获并正确存储'deptid')

下进行。

相关问题