开发者

Help needed in changing these all Queries to dept oriented

I am getting my deptid like this

$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

I need the Queries to be changed into dept... so that i can update the values of specific departments...


The PHP code is horrible - and fails to provide any relevant information to your question.

We would need to see your data schema.

I expect you'd need to re-write every SELECT statement (assuming that the 'deptid' is currently being captured and stored correctly)

C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜