Codeigniter PHP Foreach duplicate post - php

img
Every time I add a second comment, my post is duplicated. This appeared when I included comments in the system.
My code is below. Posts are duplicated every time I add a new comment.
1 comment = 1 post; 2 comments = 2 post; 3 comments = 3 post[...]
My Controller:
public function index()
{
if($this->session->userdata('u_logged') == TRUE)
{
$config = array();
$config['base_url'] = base_url().'core/index';
$config['total_rows'] = $this->core_model->types_count();
$config['per_page'] = 4;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination noborder'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled noborder'><li class='active noborder'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['results'] = $this->core_model->fetchTypes($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$data['notifications'] = $this->core_model->getLastNotifications();
$this->loadTemplate('pages', 'index_view', $data);
if(!empty($this->input->post('comm')))
{
$this->core_model->addComment();
}
}
else if($this->session->userdata('u_logged') == FALSE)
{
$this->loadTemplate('pages', 'index_view', '0');
}
}
My Model
public function types_count()
{
return $this->db->count_all('types');
}
public function fetchTypes($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->order_by('t_id', 'DESC');
$this->db->from('types');
$this->db->join('comments', 'comments.c_type_id = types.t_id');
$query = $this->db->get();
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
return false;
}
public function addComment()
{
$text = $this->input->post('inputComment');
$authorid = $this->session->userdata('u_id');
$typeid = $this->input->post('t_id');
$this->db->select('c_date');
$this->db->where('c_author', $authorid);
$query = $this->db->get('comments');
$data = $query->result();
if($query->num_rows() > 0)
{
if($data[0]->c_date - time() < -120)
{
$data = array(
'c_author' => $authorid,
'c_date' => time(),
'c_show' => '1',
'c_text' => $text,
'c_type_id' => $typeid
);
$this->db->insert('comments', $data);
}
else
{
echo 'poczekaj';
}
}
else
{
$data = array(
'c_author' => $authorid,
'c_date' => time(),
'c_show' => '1',
'c_text' => $text,
'c_type_id' => $typeid
);
$this->db->insert('comments', $data);
}
}
**And the view**
<?php foreach($results as $type) { ?>
<div class="panel panel-default noborder">
<div class="panel-body">
<div class="media noboder">
<div class="media-left">
<img class="media-object" style="width: 48px;" src="https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/13413743_1729080443973113_1289643015497858641_n.jpg?oh=98e497c14d65c2102bd9a41777447937&oe=582E9E1E">
</div>
<div class="media-body">
<h4 class="media-heading"><strong>Rafał Chojnowski</strong><small class="pull-right"><?php if($type->t_type_for == '0') { echo 'TYP DARMOWY'; } else { echo 'TYP PREMIUM'; } ?></small></h4>
<small><?php echo mdate($dateString, $type->t_date); ?></small><br />
<p>
<?php echo $type->t_match.', liga '.$type->t_league.', typ '.$type->t_type.', rozpocznie się '.$type->t_start_date.'. Kurs: '.$type->t_course.' '.$type->t_comment; ?>
</p>
</div>
<hr>
<?php foreach($results as $comment) { ?>
<div class="media-left">
<img class="media-object" style="width: 32px;" src="https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/13001028_1523205167987703_4311803603524761516_n.jpg?oh=fb2068c87060975ab7187cde7f1a161f&oe=57EA8DA5">
</div>
<div class="media-body">
<h6 class="media-heading"><strong>Tomasz Chwicewski</strong> <small><?php echo mdate($dateString, $comment->c_date); ?></small></h6>
<?php echo $comment->c_text; ?>
</div>
<br />
<?php } ?>
<?php $hidden = array('t_id' => $type->t_id, 'c_author' => $this->session->userdata('u_id'), 'comm' => '1'); ?>
<?php echo form_open('core/index', '', $hidden); ?>
<div class="input-group">
<input type="text" class="form-control input-sm noborder" name="inputComment" placeholder="Dodaj komentarz">
<span class="input-group-btn">
<button class="btn btn-primary btn-sm noborder" type="submit">Dodaj</button>
</span>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
<?php } ?>

Related

Codeigniter - Pagination not working

I'm having some problems with Codeigniter and the pagination. The problem is that I get all the results/posts on all pages.
I'm having some problems with Codeigniter and the pagination. The problem is that I get all the results/posts on all pages.
Here is my Controller Code:
public function __construct()
{
parent::__construct();
$this->load->model('SS_shilpi_model');
$this->load->library('form_validation');
$this->load->library('pagination');
}
public function category(){
$cid = $this->input->post('cid');
if(isset($_GET['cid']))
{
$cid = $_GET['cid'];
$this->SS_shilpi_model->catr3($cid);
$this->SS_shilpi_model->catr3_nr($cid);
}
$config = [
'base_url' => base_url('category/?cid='. $cid .' '),
'per_page' => 12,
'total_rows' => $this->SS_shilpi_model->catr3_nr($cid),
];
$config['full_tag_open'] = '<ul style="overflow: hidden;" class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tagl_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tagl_close'] = '</li>';
$config['first_link'] = 'First <i class="fa fa-caret-left fa-2x push-left-5 pull-right green-text"></i>';
$config['first_tag_open'] = '<li class="page-item disabled">';
$config['first_tagl_close'] = '</li>';
$config['last_link'] = '<i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i> Last';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tagl_close'] = '</a></li>';
$config['attributes'] = array('class' => 'page-link');
$this->pagination->initialize($config); // model function
$data['catr3d'] = $this->SS_shilpi_model->catr3($cid, $config['per_page'], $this->uri->segment(3)); // list of Category Details
// end pagination
$this->load->view('shilpi/category',$data);
}
My Model Code :
public function catr3($cid){
$this->db->select('');
$this->db->order_by('id', 'DESC');
$this->db->where('category_id',$cid);
$query = $this->db->get('all_posts');
return $query->result();
}
public function catr3_nr($cid){
$this->db->select('');
$this->db->order_by('id', 'DESC');
$this->db->where('category_id',$cid);
$query = $this->db->get('all_posts');
return $query->num_rows();
}
My view code :
<div id="catdata" class="col-xs-12 no-pull push-up-5 push-down-5 briefs">
<?php
$count =1;
foreach($catr3d as $r)
{
if($count%4 == 1)
{
echo '<div class="col-xs-12 no-pull push-down-5">';
}
?>
<div class="col-sm-3 col-xs-12 no-pull-left pull-right-5">
<div class="brief whitish-bg pull-5">
<p class="red-text no-push">
<?php echo $r->short_title; ?>
</p>
<a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>">
<h5 class="blue-text font17 push-up-5">
<?php echo $r->title; ?>
</h5>
</a>
<p>
<a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>">
<img src="<?php echo base_url(); ?>upload/images/<?php echo $r->photo;?>" height="75" width="100" class="pull-left push-right-5 push-up-5"></img>
</a>
<?php
$string = $r->news;
$string = strip_tags($string);
if (strlen($string) > 500) {
$pos=strpos($string, ' ', 900);
$stringCut=substr($string,0,$pos );
echo $stringCut;
}
else {
echo $string;
}
?>
<i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i>
</p>
</div>
</div>
<?php
if ($count%4 == 0)
{
echo "</div>";
}
$count++;
?>
<div class="clear: both"></div>
<?php
}
if ($count%4 != 1) echo "</div>";
?>
<?= $this->pagination->create_links() ?>
</div>
Add This to Controller start and limit to your model function argument
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['posts'] = $this->post->get_posts($config["per_page"], $page);
And following to model function get_posts
$this->db->limit($limit, $start);

codeigniter pagination in multiple table joins displying error Invalid argument supplied for foreach()

I have a problem with pagination.when I click on the next but it brings the above error, but when I click on the previous link it works normally. here is my code for the controller:
public function categoryfour()
{
$config = array();
$config["base_url"] = base_url() . "bulletins/categoryfour";
$total_row = $this->news_model->record_count_category_four();
$config["total_rows"] = $total_row;
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["posts"] =$this->news_model->get_news_cat_four($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["pages"] = explode(' ',$str_links );
$this->load->view('category_one',$data);
}
here is the code for the model:
function get_news_cat_four($limit, $start)
{
$this->db->select('news.id as newsId,news_category.id as catId,users.id as userId,news.*,news_category.*,users.*,comments.*, COUNT(comments.post_id) as num_comments');
$this->db->join('users' , 'users.id = news.user_id');
$this->db->join('news_category' , 'news_category.cat_id = news.news_id');
$this->db->join('comments' , 'comments.post_id = news.id');
$this->db->group_by('comments.post_id');
$this->db->order_by('news.date_added','desc');
$this->db->where('news.news_id',4);
$this->db->limit($limit, $start);
$query = $this->db->get("news");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;}
and finally the view:
<div id="page-content" class="single-page container">
<div class="gutter-7px">
<div id="main-content" class="col-md-8 fix-right">
<article class="single-post">
<?php if(count($posts)) {
foreach($posts as $n){ ?>
<div class="entry-header">
<h1 class="entry-title"><?php echo $n->title;?></h1>
<span> <i class="fa fa-calendar"></i> <?php echo date( 'F jS, Y g:i a' , strtotime($n->date_added))?>/
<i class="fa fa-comment-o"></i>
<?php echo $n->num_comments;?>/<i class="fa fa-user"></i>
<?php echo $n->username?></span>
</div>
<div class="post-thumbnail-wrap"><a href="<?php echo base_url();?>bulletins/view/<?php echo $n->newsId?>"><img src="<?php echo base_url('assets/images/'.$n->image)?>"
style="width:800px;height:500px" /></a></div>
<div class="entry-content">
<p><?php echo substr(strip_tags($n->content), 0, 200).'...';?></p>
Read More...
<?php }}?>
</div>
</article>
<div id="pagination">
<ul class="pagination">
<!-- Show pagination links -->
<?php foreach ($pages as $link) {
echo "<li>". $link."</li>";
}
?>
</div>
</div>
</div>

Codeigniter pagination showing duplicate records with page query string

i have created pagination with codeigniter 3.
On every page i am getting same results:
my final url seems like: http://localhost/shoping/products/mobile-phones?cid=3&page=2
Controller file:
public function category(){
$category_id = $this->input->get('cid', TRUE);
$slug = $this->uri->segment(2);
$sortby = $this->input->get('sort', TRUE);
$sorttype= 'ASC';
$limit = 10;
$config = array();
$config['base_url'] = base_url() . 'products/'.$slug.'?cid='.$category_id;
$config['total_rows'] = $this->Product_model->category_product_count($category_id);
$config['per_page'] = $limit;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'page';
// $config["uri_segment"] = 3;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['next_link'] = '»';
$config['cur_tag_open'] = '<li><a class="current">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
if($this->uri->segment(2) > 0){
$page = ($this->uri->segment(2) + 0)*$config['per_page'] - $config['per_page'];
}
else{
$page = $this->uri->segment(2);
}
$data["links"] = $this->pagination->create_links();
if($data["links"]!= '') {
$data['pagermessage'] = 'Showing '.((($this->pagination->cur_page-1)*$this->pagination->per_page)+1).' to '.($this->pagination->cur_page*$this->pagination->per_page).' of '.$config['total_rows'];
}
if($this->input->get('sort')=='pricelow'){
$sortby = 'price';
$sorttype= 'ASC';
}
elseif($this->input->get('sort')=='pricehigh'){
$sortby = 'price';
$sorttype= 'DESC';
}
elseif($this->input->get('sort')=='new'){
$sortby = 'updated_on';
$sorttype= 'DESC';
}
elseif($this->input->get('sort')=='popularity'){
$sortby = 'price';
$sorttype= 'DESC';
}
else{
$sortby = 'title';
$sorttype= 'ASC';
}
//Get all products
$data['products_by_category'] = $this->Product_model->get_products_by_category($category_id, $config["per_page"], $page, $sortby, $sorttype);
// echo $config['total_rows'];
// Load View
$data['main_content'] = 'public/products_category';
$this->load->view('public/layouts/home_main', $data);
}
Model File:
public function get_products_by_category($category_id, $limit, $start='', $shortby='', $shorttype=''){
$this->db->select('*');
$this->db->where('category_id', $category_id);
$this->db->limit($limit, $start);
$this->db->order_by($shortby, $shorttype);
$query = $this->db->get('products');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
and view file:
<?php foreach($products_by_category as $product): ?>
<div class="col-sm-4 col-md-4 col-lg-3">
<div class="single-product" style="height:300px;margin-bottom:10px">
<span class="sale-on">sale</span>
<div class="product-image">
<div class="show-img">
<a href="<?php echo base_url();?><?php echo $product->slug.'?sid='.$product->id;?>">
<img src="<?php echo base_url(); ?>assets/images/products/<?php echo $product->image;?>" alt="<?php echo $product->title;?>" height="150" width="150">
</a>
</div>
</div>
<div class="prod-info">
<h2 class="pro-name">
<?php echo $product->title.$product->id;?>
</h2><br>
<div class="price-box">
<div class="price">
<span><i class="fa fa-inr"></i><?php echo $product->price;?></span>
</div>
<div class="old-price">
<span><i class="fa fa-inr"></i><?php echo $product->mrp_price;?></span>
</div>
</div>
<div class="actions">
<span class="new-pro-wish">
<i class="fa fa-heart-o"></i>
</span>
<span class="new-pro-compaire">
<i class="fa fa-bar-chart"></i>
</span>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Instead of $this->uri->segment(2), use $this->input->get('page', TRUE).
See CI_Input::get for more information on how you can get query string variables.

Pagination in Codeigniter 3

I'm trying to make a pagination for a query. I can't figure why is the reason that the pagination doesn't work, it shows the pagination links, right now I have 15 records and I want to show that in batches of 5, but in the page # 1 I see the 15 records and when I click in the second page link I have an error that says that the page doesn't exist.
This is my model "searchCases":
//Function to get the active cases
function getCases(){
$query = $this->db->
select('*')->
from('customer_complaint')->
where('active', 1)->
get();
return $query->result();
}
//Function to get the number of opened cases
function countCases(){
$query = $this->db->
select('*')->
from('customer_complaint')->
where('active', 1)->
get();
return $query->num_rows();
}
// Function to retrieve a list of all the records of the table an the params $limit and $start to
// determine the number of records to return and what record to start from.
function fetchCases($limit, $start){
$this->db->limit($limit, $start);
$query = $this->db->
select('*')->
from('customer_complaint')->
where('active', 1)->
get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
Now this is my Controller "opened_cases":
public function index(){
$this->load->view('headers');
$this->load->view('navbar');
$data['query'] = $this->searchCases->getCases();
$config['base_url'] = base_url().'index.php/opened_cases/';
$config['total_rows'] = $this->searchCases->countCases();
$config['per_page'] = 5;
$config['uri_segment'] = 2;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["results"] = $this->searchCases->
fetchCases($config["per_page"], $page);
$this->load->view('opened_cases', $data);
$this->load->view('footer');
}
and my View "opened_cases":
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Search Results:
</div><!--End of Panel Heading-->
<div class="panel-body">
<table class="table" style="text-align: center">
<tr>
<td>Case ID</td>
<td>Received Date</td>
<td>Folio</td>
<td>Transactions Date</td>
<td>Reason of Complaint</td>
<td>Source of Complaint</td>
<td>Files</td>
</tr>
<?php
foreach ($query as $row) {?>
<tr>
<td><?= $row->complaint_id?></td>
<td><?= date('m/d/Y', strtotime($row->received_date))?></td>
<td><?= $row->folio?></td>
<td><?= date('m/d/Y', strtotime($row->tx_date))?></td>
<?php
$this->load->model('searchCases');
$id=$row->complaint_id;
$reason_id=$this->searchCases->reason($id);
$source_id=$this->searchCases->source($id);
foreach ($reason_id as $rsn) {
if($rsn->reason == 'Others'){
echo "<td class='text-left'>".$rsn->reason.": ".$row->other_reason."</td>";
}else{
echo "<td class='text-left'>".$rsn->reason."</td>";
}
}
foreach ($source_id as $src) {
echo "<td>".$src->source."</td>";
}
?>
<td><?php
$folder = $row->complaint_id;
$path_root = "upload/".$folder."/";
$dir = scandir($path_root, 1);
$array_lenght = count($dir)-2;
if($array_lenght>=1){?>
<span class="glyphicon glyphicon-paperclip"></span>
<?php } ?></td>
</tr>
<?php }?>
</table>
</div><!--End of body panel-->
<div class="panel-footer text-center">
</div><!--End of Panel Footer-->
</div><!--End of Panel-->
<div class="col-sm-12 text-center">
<?= $this->pagination->create_links() ?>
</div> <!-- End of pagination -->
</div>
Here is an image of my view:
15 records instead of 5
UPDATE:
I realize my mistake:
$data['query'] = $this->searchCases->getCases(); //I deleted this line, because i was getting all the results of the query.
and now in the view I replace $results instead $query in the foreach cycle and now I can see the 5 results per page that I'm asking for.
foreach ($query as $row) {?>
<tr>...
Changed to:
foreach ($results as $row) {?>
<tr>...
But now when I click on the link for the second page I have the same error 404 that I had from the start.
Try this $config['base_url'] = base_url().'index.php/opened_cases/index';
And change this $config['uri_segment'] = 3;

CodeIgniter pagination onclick

Good day,
Quick question,
I am using CI's pagination to my project,
it works perfectly, but i wanted to add some
filters on it.
i.e. I need to catch its click event.
although I can catch already its click event using this
$("ul.pagination > li a[href]").click(function(e){
loadingStart();
});
my problem is it still redirect to the next page,
what I need is something like this.
if(myVar == 0) {
//do not redirect
} else {
//redirect.
}
Use e.preventDefault(); and then execute your custom function
If you want filter for pagination that use $_GET ... no redirect in js (You can not undo, etc.).
I show you how I do:
Controller:
/**
Example list
**/
public function index()
{
$page = ($this->input->get('page') AND $this->input->get('page')>1)?(intval($this->input->get('page'))-1)*9:1; #9 item for page
#where if isset($_GET)
$where = array();
if($this->input->get('city')) {
$where['users.city'] = $this->input->get('city');
}
if($this->input->get('street')) {
$where['users.street'] = $this->input->get('street');
}
#load model
$this->load->model('users_m');
$view_data['users'] = $this->users_m->GetAll($where,$page,array('users.register_date'=>'DESC'))->result();
//pagination library
$this->load->library('pagination');
$config['base_url'] = site_url('/users');
$config['total_rows'] = $this->users_m->GetAll($where,0)->num_rows();
$config['per_page'] = 9;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'page';
$config['reuse_query_string'] = TRUE;
$config['use_page_numbers'] = true;
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
//variable to template
$view_data['pagination'] = $this->pagination;
$this->load->view('/users/index',$view_data);
}
Model: users_m
/**
* Get all users example
**/
public function GetAll($where=array(),$page=1,$order_by=array(),$limit=9)
{
$this->db->select('users.*');
#order by
if(count($order_by)>0)
{
foreach($order_by as $key=>$value)
{
$this->db->order_by($key,$value);
}
}
$this->db->where($where);
#show all (for pagination calculate)
if($page==0) return $this->db->get_where('users',$where);
#show single page
return $this->db->get_where('users',$where,$limit,(($page==1)?$page-1:$page));
}
And view:
<div id="search_bar">
<?php echo form_open(site_url('/users'),array('class'=>'form-inline','method'=>'get'));?>
<div class="form-group col-lg-2 col-md-4 col-sm-4">
<select name="type" class="form-control">
<option value="" disabled="disabled" selected="selected" >City</option>
<option value="1" <?php if(set_value('city')==1) echo 'selected';?>>London</option>
<option value="2" <?php if(set_value('city')==2) echo 'selected';?>>Warsaw</option>
</select>
</div>
<button type="submit" class="btn btn-primary" style="margin-top:-10px;">Search</button>
<?php echo form_close();?>
</div>
<hr/>
<div id="grid-user" class="row">
<table>
<tbody>
<?php foreach($users as $user):?>
<tr>
<td><?php echo $user->id;?></td>
<td><?php echo $user->firstname;?></td>
<td><?php echo $user->lastname;?></td>
<td><?php echo date("d.m.Y",strtotime($user->register_date));?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-lg-12">
<div style="float:right;"><?php echo $pagination->create_links();?></div>
</div>
</div>
I sorry for my english.
This is example (not checked, written from memory).
Try it :)

Categories