Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class user
- public function setGroup($id)
- { $this->_db->get('groups',array('id','>','0'));
- $results = $this->_db->results();
- $exist=false;
- foreach ($results as $result) {
- echo $result->id,'<br>';
- echo $id,'<br>';
- if ($result->id===$id){
- $exist=true;}
- }
- if (!$exist){
- echo "not done ";
- return false ;
- }else{
- echo 'done';
- try {
- $this->update(array(
- 'group'=>$id));
- }catch (Exception $e ){
- die($e->getMessage());
- }
- }
- }
- ************************
- class user
- public function update($fields = array(),$id=null){
- if (!$id && $this->isLoggedIn){
- $id=$this->data()->id;
- }
- if (!$this->_db->update('users',$id,$fields)){
- throw new Exception('There was a problem updating');
- }
- }
- *******************
- class DB
- public function update($table,$id,$fields){
- $set='';
- $x=1;
- foreach ($fields as $name=>$value ){
- $set .= "{$name}=?";
- if ($x<count($fields)){
- $set .=',';
- }
- $x++;
- }
- $sql = "UPDATE {$table} SET {$set} WHERE id = {$id}";
- echo $sql ;
- var_dump($fields);
- if(!$this->query($sql,$fields)->error()){
- return true ;
- }
- return false ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement