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

#11
[eluser]yousuf_007sys[/eluser]
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.

tc

#12
[eluser]JayTee[/eluser]
Quick reference on the MVC pattern:

http://codeigniter.com/wiki/MVC/

#13
[eluser]yousuf_007sys[/eluser]
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

#14
[eluser]NateL[/eluser]
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

#15
[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..

#16
[eluser]Hakkam[/eluser]
Hi Yusuf,

Please try debug it using print_r . Step by step



CONTROLLER

class Main extends Controller{


function index(){
$this->load->helper('form');
$this->load->view('profile');
}

function createProfile(){
$this->load->helper('url');
//if ($this->input->post('name')){
$this->load->model('Mprofile','',TRUE);
$this->Mprofile->addData();
redirect('main/myResult','refresh');
//}
//else{
// redirect('main/createProfile','refresh');
//}
}


function myResult(){
$this->load->helper('url');
$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.

print_r($data['result']);exit();

If any array result than try print_r in views


$data['page_title']="Yousuf";
$this->load->view('viewentry',$data);
}
}
?>


VIEW-2
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>

please try print_r the result, is there any result data ?
print_r($result);exit();

<?php foreach($result as $row):?>
<h3>&lt;?=$row->name?&gt;</h3>
<p>&lt;?=$row->address?&gt;</p>
<h3>&lt;?=$row->phonenumber?&gt;</h3>
<p>&lt;?=$row->email?&gt;</p>
<h3>&lt;?=$row->occupation?&gt;</h3>
<p>&lt;?=$row->interests?&gt;</p>
<h3>&lt;?=$row->filename?&gt;</h3>

<br />
&lt;?php endforeach;?&gt;
&lt;/body&gt;
&lt;/html&gt;[/quote]

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

#18
[eluser]yousuf_007sys[/eluser]
thank you very much for all the help...finally sorted out the problem,

#19
[eluser]ntheorist[/eluser]
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

n


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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