CodeIgniter Forums
Edit Pages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Edit Pages (/showthread.php?tid=66040)

Pages: 1 2 3


RE: Edit Pages - InsiteFX - 08-29-2016

Its simple after updating the record he need to re-fetch the data record by id to re-display it.

Hello Wall!


RE: Edit Pages - albertleao - 08-29-2016

Davy_yg. Please go to w3schools, udemy, codeacademy, and learn some basic php before asking people here for answers to basic php questions.


RE: Edit Pages - Joel Catantan - 08-29-2016

(08-28-2016, 04:02 PM)davy_yg Wrote: I update it into something else:

models/Mpages.php

PHP Code:
public function add_settings()
 {
 
 
$data = array(
 
'email' => $this->input->post('email'),
 
'site_name' => $this->input->post('sitename'),
 
'meta_title' => $this->input->post('title'),
 
'meta_keyword' => $this->input->post('keyword'),
 
'meta_description' => $this->input->post('description'),
 
'facebook' => $this->input->post('facebook'),
 
'twitter' => $this->input->post('twitter'),
 
'rss' => $this->input->post('rss'
 );
 
 
$query $this->db->update('setting'$data);
 return 
$query->result_array();
 
 
 } 

There is a new error that I do not know how to fix it:

Fatal error: Call to a member function result_array() on boolean in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\models\Mpages.php on line 197
A PHP Error was encountered
Severity: Error
Message: Call to a member function result_array() on boolean
Filename: models/Mpages.php
Line Number: 197
Backtrace:



@davy_yg is your "setting" table store only 1 record? It seems to me since you just updating the record in that table without condition. What if you haven't yet any record in this "setting" table? If that is the case you should insert the settings first and the next execution will be updating.

Mpages.php

PHP Code:
function settings()
{
    
$data = array(
        
'email' => $this->input->post('email'),
        
'site_name' => $this->input->post('sitename'),
        
'meta_title' => $this->input->post('title'),
        
'meta_keyword' => $this->input->post('keyword'),
        
'meta_description' => $this->input->post('description'),
        
'facebook' => $this->input->post('facebook'),
        
'twitter' => $this->input->post('twitter'),
        
'rss' => $this->input->post('rss')
    );

    if(
$this->db->from('settings')->count_all_results())
 
   {
 
       $success $this->db->update('setting'$data);
 
   }
    else
 
   {
 
       $success $this->db->insert('setting'$data);
 
   }

 
   // the update and insert method only return boolean [true means success, false means failed]
 
   if($success)
 
   {
        
// meaning success so return the record from setting table
        // again, i assumed that the record from table is just 1 so this function only return a single result if success
 
       return $this->db->get('setting')->row();
 
   }

 
   return false;