Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1.  class user
  2. public function setGroup($id)
  3.     {   $this->_db->get('groups',array('id','>','0'));
  4.         $results = $this->_db->results();
  5.         $exist=false;
  6.         foreach ($results as $result) {
  7.             echo $result->id,'<br>';
  8.             echo $id,'<br>';
  9.             if ($result->id===$id){
  10.                 $exist=true;}
  11.         }
  12.         if (!$exist){
  13.             echo "not done ";
  14.             return false ;
  15.         }else{
  16.             echo 'done';
  17.             try {
  18.                 $this->update(array(
  19.                     'group'=>$id));
  20.             }catch (Exception $e ){
  21.                 die($e->getMessage());
  22.             }
  23.  
  24.         }
  25.     }
  26. ************************
  27. class user
  28.  public function update($fields = array(),$id=null){
  29.         if (!$id && $this->isLoggedIn){
  30.             $id=$this->data()->id;
  31.         }
  32.         if (!$this->_db->update('users',$id,$fields)){
  33.             throw new Exception('There was a problem updating');
  34.         }
  35.     }
  36. *******************
  37. class DB
  38. public function update($table,$id,$fields){
  39.         $set='';
  40.         $x=1;
  41.         foreach ($fields as $name=>$value ){
  42.             $set .= "{$name}=?";
  43.                 if ($x<count($fields)){
  44.                     $set .=',';
  45.                 }
  46.                 $x++;
  47.         }
  48.         $sql  = "UPDATE {$table} SET {$set} WHERE id = {$id}";
  49.         echo $sql ;
  50.         var_dump($fields);
  51.         if(!$this->query($sql,$fields)->error()){
  52.             return true ;
  53.         }
  54.         return false ;
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement