problem learning CI |
[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
[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
[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
[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..
[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><?=$row->name?></h3> <p><?=$row->address?></p> <h3><?=$row->phonenumber?></h3> <p><?=$row->email?></p> <h3><?=$row->occupation?></h3> <p><?=$row->interests?></p> <h3><?=$row->filename?></h3> <br /> <?php endforeach;?> </body> </html>[/quote]
[eluser]Thorpe Obazee[/eluser]
Hakkam, plese enclose in [ code][/ code] tags?
[eluser]yousuf_007sys[/eluser]
thank you very much for all the help...finally sorted out the problem,
[eluser]ntheorist[/eluser]
fyi, a nice way to handle forms is to name each of the fields by array vs individually, so instead of <input name="name" type="text"> <input name="email" type="text"> <input name="address" type="text"> and having to use $this->input->post() on each, you use <input name="form[name]" type="text"> <input name="form[email]" type="text"> <input name="form[address]" type="text"> 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 |
Welcome Guest, Not a member yet? Register Sign In |