Welcome Guest, Not a member yet? Register   Sign In
Edit Pages
#21

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

Hello Wall!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#22

Davy_yg. Please go to w3schools, udemy, codeacademy, and learn some basic php before asking people here for answers to basic php questions.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#23

(This post was last modified: 08-30-2016, 02:50 AM by Joel Catantan.)

(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;

[Just a programmer] Cool [/Just a programmer]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB