• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving datas from database and displaying it in view

#1
[eluser]kasirajan PHP[/eluser]
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...

#2
[eluser]TWP Marketing[/eluser]
[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:
Code:
...
$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
Code:
...
function read_some_table()
{
  $query = $this->db->get('some_table_name'); // read all records form the table
  if( $query->num_rows() > 0 )
  {
   return( $query->result_array() ); // return the data as an array
  }else{
   return( FALSE );
  }
}
...

In a view file myview.php:
Code:
...
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...

#3
[eluser]kasirajan PHP[/eluser]
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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