Question

There is an error in my code but the code works perfectly. I mean all the values are inserted in the database but there is an error like this on the screen:

Severity: Notice

Message: Array to string conversion

Filename: models/some_model.php

Line Number: 106

This is my code:

View:

<?php foreach($app as $row){
    echo "<tr><td><input type=checkbox name=appname[]  value='".$row->app_name."'/>".$row->id."</td><td>".$row->app_name."</td><tr>".
?>  

Controller:

public function hide(){
    $this->load->model('some_model');
    $visi = $this->input->post('appname');
    $success = $this->some_model->hideApp($visi);

    foreach($visi as $key=>$value)
    {
    $success = $this->some_model->hideApp($visi[$key]);
    }

    if($success == TRUE)
        $this->hideApp_page(TRUE);
    else $this->hideApp_page(FALSE);
}

Model:

public function hideApp($visi){
    $visi = $this->db->escape_str($visi);
    $queryStr = "UPDATE appwarehouse.application_table SET visibility='hidden' where app_name='$visi';"; /* this is line 106*/
    $query = $this->db->query($queryStr);
    return $query;
}
Was it helpful?

Solution

$visi is array like [1,2,3,4]
when you put $visi in hideApp()
it will be display "array to string error"
so maybe you can remove this line $success = $this->some_model->hideApp($visi);
you have already do some_model->hideApp($visi[$key]) in the foreach loop
so i don't know why you write this$success = $this->some_model->hideApp($visi);

if you still want to run $success = $this->some_model->hideApp($visi);
you have to put $visi into a string

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top