CodeIgniter Forums

Full Version: Adding text to record field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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' );
        }

    } 
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.