EllisLab text mark
Advanced Search
     
Retrieving datas from database and displaying it in view
Posted: 02 November 2012 02:16 AM   [ Ignore ]
Joined: 2012-11-02
5 posts

Hi, i need ur idea to retrieve datas from database and display the same in view while loading itself.

I had created one model and written query in that and i had called that model from controller index function, so that it ll display in view while loading. but i dono how to display it in view after retrieving it from model. .

Pls help..
Thanks in advance…

 Signature 

kasirajan

 
Posted: 02 November 2012 07:11 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-12-19
612 posts

[EDIT] Apologies, I misread your question, you do have database access and do want to use a model… I need more coffee. I’ve changed this reply to access a db table from the model

In the controller:

...
$data['some_data'$this->Mymodel->read_some_table(); // read the db table
...
$this->load_view('myview',$data); // pass the data array to your view where it will be exploded, see below 

In the model file mymodel.php

...
function 
read_some_table()
{
  $query 
$this->db->get('some_table_name'); // read all records form the table
  
if( $query->num_rows() > )
  
{
   
return( $query->result_array() ); // return the data as an array
  
}else{
   
return( FALSE );
  
}
}
... 

In a view file myview.php:

...
foreach( 
$some_data as $key => $value)
{
  
echo 'This is the array key value: '.$key.'<br />';
  echo 
$value['field_name'].'<br />'// echo the data element in the view (note that the array $data has been exploded.
  
echo $value['another_field_name'].'<br />';
}
... 

This is VERY basic code and you will find it all in the User Guide…

 Signature 

CI 2.1.3, Linux, LAMP. We also like Gold and Silver…
Blame the hammer, it is obviously the guilty party…
User Guide? Nobody told me there was a User Guide!

 
Posted: 05 November 2012 01:57 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-11-02
5 posts

ok thank you. I had retrieved datas from database and displayed it in my page. It’s working well and now i got another question for you. I need to do, insert,update,delete in same page. Pls help me with some sample codings. . .

Awaiting your reply.

Regards,
Kasirajan.C

 Signature 

kasirajan