• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem learning CI

Sorry the error is the following:
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: libraries/Loader.php(673) : eval()'d code

Line Number: 6

Actually I went to input data from a form send it to my my database and retrieve all the data from my database table.


Quick reference on the MVC pattern:


thanks for the MVC pattern

In the function myResult(),I am retrieving information from the database using the model class and then I am passing information to the View-2 to be displayed. I am having problems with foreach statement

hope someone can help me out

NetTuts released its first video of a CodeIgniter series. Check it out.

Also, I bought the first 2 videos from BinaryCake and am really looking forward to more releases

[eluser]Zeeshan Rasool[/eluser]
hi yousuf, i think you have problem in your foreach loop try to print out array in view with print_r If it contains result.
I think you have empty array in foreach..

Hi Yusuf,

Please try debug it using print_r . Step by step


class Main extends Controller{

function index(){

function createProfile(){
//if ($this->input->post('name')){
// redirect('main/createProfile','refresh');

function myResult(){
$this->load->model('Mprofile', '', true);
$data['result'] = $this->Mprofile->getData();

Please try print_r in here then exit, to know if is there any data result.


If any array result than try print_r in views



please try print_r the result, is there any result data ?

<?php foreach($result as $row):?>

<br />
&lt;?php endforeach;?&gt;

[eluser]Thorpe Obazee[/eluser]
Hakkam, plese enclose in [ code][/ code] tags?

thank you very much for all the help...finally sorted out the problem,

fyi, a nice way to handle forms is to name each of the fields by array vs individually, so instead of

&lt;input name="name" type="text"&gt;
&lt;input name="email" type="text"&gt;
&lt;input name="address" type="text"&gt;

and having to use $this->input->post() on each, you use

&lt;input name="form[name]" type="text"&gt;
&lt;input name="form[email]" type="text"&gt;
&lt;input name="form[address]" type="text"&gt;

and in your controller use $this->input->post('form'); It will contain the entire array from the form and can be validated easliy and sent directly to the model. For model forms typically i use this and name the form according to model, ie $user_data = $this->input->post('user',TRUE);

glad you got it to work tho


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.