i want to fetch the content stored in my database on to the webpage, its working but the issue im facing from the below code is that, all the rows are getting fetched. but instead i want to fetch each row of the database on each of the different section. i mean to say is that, the content of 1st row of database should be displayed on the first row section of my view page and the content of 2nd row of database should be displayed on my second row section. please can any one help me. i dont know where im going wrong
<!--controller-->
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
//load database libray manually
$this->load->database();
//load Model
$this->load->model('Contact_model');
// load form and url helpers
$this->load->helper(array('form', 'url'));
// load form_validation library
$this->load->library('form_validation');
}
function deesha()
{
$this->load->model("Contact_model");
$data['results'] = $this->Contact_model->getAllRecords10();
$this->load->view('homeview',$data);
}
}
?>
<!--model-->
<?php
class Contact_model extends CI_Model
{
function getAllRecords10()
{
//$this->load->library("database");
$results = array();
$this->db->select('title,content');
$this->db->from('test');
//$this->db->limit(1);
$q = $this->db->get();
if($q->num_rows() > 0)
{
$results= $q->result();
}
return $results;
}
}
?>
<!--view-->
<body>
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-4">
<!-- first row should be displyed-->
<table>
<?php
if( !empty($results) ) {
foreach($results as $row) {
echo '<tr>';
echo '<h3>'.$row->title.'</h3>';
echo '<p>'.$row->content.'</p>';
echo '</tr>';
}
}
?>
</table>
</div>
<div class="col-sm-4">
<!-- second row should be displyed -->
<table>
<?php
if( !empty($results) ) {
foreach($results as $row) {
echo '<tr>';
echo '<h3>'.$row->title.'</h3>';
echo '<p>'.$row->content.'</p>';
echo '</tr>';
}
}
?>
</table>
</div>
</div>
</div>
</body>
first_content,
second_content
or it is fix name – Pradeep