Welcome Guest, Not a member yet? Register   Sign In
Please Help Me - How can update another table?
#1
Heart 
(This post was last modified: 05-09-2017, 06:44 PM by efeyusuf.)


.php   admin_makale_model.php (Size: 14.39 KB / Downloads: 110)
.php   admin_makale_model.php (Size: 14.39 KB / Downloads: 110) Please help me, I am learning codeigniter.. thank you..

When user added content I want to give points. 

It has 2 tables. ''User_detail and Makale''

For example: 

user added content. And I confirm (status: 1) user has to take points.

user_detail->id = makale=user_id
[Image: GBj2q6.png]

[Image: z3NlW6.png]

How Can I Do?


public function givepoints($id)

   {
$this->db->select('*');
$this->db->from('makale');
$this->db->join('user_detail', 'user_detail.id = makale.user_id');
$query = $this->db->get();

$this->db->set('puan', 'puan+50',FALSE);
$this->db->where("id", $id);
$this->db->update("user_detail");
    }



Admin Controller:
Code:
   public function updateStatus()
   {
       // Yetki Kontrolü
       $this->panel->permission($this->module, 'edit', TRUE);

       // Düzenlenecek Kayıt
       $record = $this->appmodel->record((int) $this->uri->segment(4));

       // Durum Kontrolü ve Veritabanı İşlemi
       if ((int) $record->status === 1) {
           $success = $this->appmodel->updateStatus($record->id, 2);
       } else {
           $success = $this->appmodel->updateStatus($record->id, 1);

       }

        $user_id = $itemi->user->id;
          if ((int) $record->status === 1) {

            $success = $this->appmodel->givepoints($record->id, 2);
       } else {

        $success = $this->appmodel->removepoints ($record->id, 1);

       }
        
        
       // İşlem Başarılı Kontrolü
       if ($success) {
            $this->panel->userlog($this->module, 'STATUS', "Kayıt durumu değiştirildi. #{$record->id}");
            $this->panel->set_alert('success', "Kayıt durumu değiştirildi. (#{$record->id})");
       } else {
            $this->panel->userlog($this->module, 'STATUS', "Kayıt durumu değiştirilemedi! #{$record->id}");
            $this->panel->set_alert('error', "Kayıt durumu değiştirilemedi! (#{$record->id})");
       }
       redirect($this->input->server('HTTP_REFERER'));
   }



Admin Content Model:

Code:
   public function updateStatus($id, $value)
   {
       return $this->db
                       ->where('id', $id)
                       ->update($this->table, array(
                                                   'status'        => $value,
                                                   'updated_date'  => $this->date->set()->mysql_datetime(),
                                               ));
   }
    
    
    
public function givepoints($id)
   {
$this->db->select('*');
$this->db->from('makale');
$this->db->join('user_detail', 'user_detail.id = makale.user_id');
$query = $this->db->get();



$this->db->set('puan', 'puan+50',FALSE);
$this->db->where("id", $id);
$this->db->update("user_detail");
    }


Attached Files
.php   admin.php (Size: 19.65 KB / Downloads: 84)
Reply


Messages In This Thread
Please Help Me - How can update another table? - by efeyusuf - 05-09-2017, 05:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB