CodeIgniter Forums
Adding text to record field - 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: Adding text to record field (/showthread.php?tid=62589)



Adding text to record field - vertisan - 08-02-2015

Hi!

I need to add text to record (NOT OVERWRITE). This is my code, but it's overwriting to field 8, and I don't know why.

CONTROLLER:
PHP Code:
    public function ServiceDecline$id "" ) {

        
$id = array( 'id' => $id );

        
$UserID $this->ion_auth->user()->row();

        
$DeclineList $this->AdminServices_model->DeclineList();
        
$DeclineList array_push$DeclineList $UserID->id );

        
$AddDeclined = array( 'odrzucili' => $DeclineList );

        
$this->AdminServices_model->DeclineService$id$AddDeclined );
        
    } 

MODELs:
PHP Code:
    public function DeclineList(  ) {
        
$query $this->db->get'services' );

        return 
$query->result();
    } 
PHP Code:
    public function DeclineService$id$AddDeclined ) {
        if ( 
$this->db->update'services'$AddDeclined$id ) ) {
            
$this->session->set_flashdata('msg''Success!');
            
redirect'service/zgloszenia' );
        }

    } 



RE: Adding text to record field - msteudel - 08-03-2015

Some things to try:

PHP Code:
$DeclineList $this->AdminServices_model->DeclineList();
$DeclineList array_push$DeclineList $UserID->id ); 

To:

PHP Code:
$DeclineList $this->AdminServices_model->DeclineList();
array_push$DeclineList $UserID->id ); 

Debug like so, make sure the $UserID->id is being added:

PHP Code:
$DeclineList $this->AdminServices_model->DeclineList();
var_dump$DeclineList );
$DeclineList array_push$DeclineList $UserID->id );
var_dump$DeclineList ); 

It might be helpful to see your database structure, as this call is confusing:

PHP Code:
$AddDeclined = array( 'odrzucili' => $DeclineList ); 

Are you saying you have a database table that only has one field in it: odrzucili

Also to store an array in the database you should serialize it.

Also in DeclineList you are potentially getting a array of arrays ( multidimensional array). I think you are confusing getting multiple results and trying to update a single result.