I am using this code to insert
$last_id = "SELECT max(id) as id from clients ";
$client_id = $this->db->query($last_id)->row();
$client_last = $client_id->id;
$data = array();
for($i=0; $i<count($res); $i++)
{
$data['user_id'] = $res[$i];
$data['client_id']=$client_last;
$this->db->insert("notifications", $data);
}
Array $res
returns values user_ids
like below:
Array
(
[0] => stdClass Object
(
[id] => 5
)
[1] => stdClass Object
(
[id] => 6
)
[2] => stdClass Object
(
[id] => 7
)
)
And variable $client_last
returns single value like 5
or 90
something like this.
In this scenario I want to insert three rows in table notifications inserting the value of $res
array and same value of $client_last
against each value of $res array
.
But in this case I am getting data base error saying:
Message: Object of class stdClass could not be converted to string
and when I print last query with $this->db->last_qery();
It shows something like this
INSERT INTO `notifications` (`user_id`, `client_id`) VALUES (, '90')
with saying sql error.