CodeIgniter: PHP Error: Invalid arg in foreach() in Table.php : line 198 CodeIgniter: PHP Error: Invalid arg in foreach() in Table.php : line 198 codeigniter codeigniter

CodeIgniter: PHP Error: Invalid arg in foreach() in Table.php : line 198


Change your $query variable to be like this:

$query = array(array('id'=>'123', 'request'=>'FARTS', 'user'=>'Steve', 'date'=>'Today'));

That method is expecting an array of arrays, even if there is no specific key=>value pair.

$query = array(array('123','FARTS','Steve', 'Today'));

In essence, that is also what your database query should be returning when you use CI's database library.

Personally, unless you are going to use data straight from the db query, I would use:

$this->table->add_row('123','FARTS','Steve', 'Today');-OR-$this->table->add_row(array('ID'=>'hello','class'=>'Today','data'=>'Displayed Text'));

As far as you database query getting the same error, I would triple check what kind of output you're actually recieving from said query.

Hope this helps