I am using CodeIgniter Framework, i have two li tag, i want to fill first li with all data of first table, and depending on the id if matched from the first table and second table i have another select query which gets data and show it in second li tag. Here is the working code in core php but cannot be run in CodeIgniter, but the problem is i only can get data from one table and passed it to view from controller.Please help me how i can use two tables data in view.
<?php
$sql = 'SELECT * FROM course_sections ORDER BY item_order ASC';
$query = $pdo->prepare($sql);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $rs) { ?>
<li style="sample_style"> <?=$rs['title'];?> </li>
<?php
$sql = 'SELECT * FROM course where itemid = :pid ORDER BY item_order ASC';
$query = $pdo->prepare($sql);
$query->bindParam(':pid', $rs['id'], PDO::PARAM_INT);
$query->execute();
$f_list = $query->fetchAll();
foreach ($f_list as $get_final_list) { ?>
<li style="sample_style"> <?=$get_final_list['title'];?> </li>
<? } } ?>
CodeIgniter Code:
Model function:
function get_all_topics()
{
$this->load->database();
$this->db->select("*");
$this->db->from("course_sections");
$this->db->order_by("item_order", "ASC");
$query=$this->db->get();
return $query->result();
}
Controller function :
function index()
{
$this->load->model('drag_drop_model');
$data['query']=$this->drag_drop_model->get_all_topics();
$this->load->helper('url');
$this->load->view('drag_drop_course_material', $data);
}