Welcome Guest, Not a member yet? Register   Sign In
how to show different row in different page from db
#1

[eluser]xpeed[/eluser]
hello i just like to know how i can show second row from db.
and another page 3rd row from db

This controller for view data from model

public function view_main_body() {
$data = array();
$data['main_body_details'] = $this->sa_model->select_main_body();
$data['admin_content'] = $this->load->view('admin/view_page_content', $data, true);
$this->load->view('admin/index', $data);
}



here is the model which show data from database

public function select_main_body() {
$this->db->select('*');
$this->db->from('tbl_main_body');
$result_query = $this->db->get();
$result = $result_query->row();
return $result;
}


here is the welcome controller which show in frontpage


public function index()
{ $data=array();
$data['menu_details'] = $this->sa_model->select_menu();
$data['maincontent']=$this->load->view('home_message',$data,true);
$this->load->view('index',$data);
}


i can show with foreach loop


<?php echo $main_body_details->main_body; ?>

this is code show fast row result but i want to show my second row from db.
another page 3rd row from db


Thanks in advance

#2

[eluser]Tpojka[/eluser]
Using MySQL LIMIT?
Code:
$query = $this->db->get('mytable', 1, 1); // first numbes means row index (second row), second number means how many rows from it

User guide.
#3

[eluser]xpeed[/eluser]
hello i just like to show second row from db. how i can ??

Thanks
#4

[eluser]Tpojka[/eluser]
What error you get when useing code I posted before?
#5

[eluser]xpeed[/eluser]
Code:
Error Number: 1066

Not unique table/alias: 'tbl_main_body'

SELECT * FROM (`tbl_main_body`, `tbl_main_body`) LIMIT 1, 1

Filename: F:\wamp\www\css3world\system\database\DB_driver.php

Line Number: 330

this error showing
#6

[eluser]Tpojka[/eluser]
In your model make another method and place next code to it:
Code:
$query = $this->db->get('tbl_main_body', 1, 1);
return $query->result();




Theme © iAndrew 2016 - Forum software by © MyBB