Selim Reza
Selim Reza

Reputation: 372

Get dynamic content from database to controller in Codeigniter

I have a table in database where I kept keywords/title/description. Now I want to get the data (content) in controller function ::::

how can I get data from database into a function of controller ::::

public function index()
{
   $data=array();

   $data['title']=" Title "; // need the title dynamic
   $data['keywords']="Keywords"; // need the keyword dynamic
   $data['keywords']="Description"; // need the description dynamic

}

Upvotes: 1

Views: 2129

Answers (3)

Muhammad
Muhammad

Reputation: 3250

try this.

$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
{
   foreach ($query->result() as $row)
   {
      $data['title'] = $row->title;
      $data['Keywords'] = $row->Keywords;
      $data['Description']= $row->Description;
   }
} 

you can use the following variables in your view file

$title, $Keywords, $Description.

Upvotes: 1

ABorty
ABorty

Reputation: 2522

try this

in controller

public function index()
{
    $data=array();
    $data['content']=$this->model_name->getContent();   

}

in model

function getContent()
{
    $data=array();
    return $data=$this->db->select('title,keywords,description')->get('table_name')->result_array();
}

This is the general way to fetch data from database. Please let me know if you face any problem.

Upvotes: 2

Nil'z
Nil'z

Reputation: 7475

Create a model function that will query the database to return your controller the results. You need to learn about CI first. Learn Codeignter first!

Upvotes: 0

Related Questions