I am new in codeigniter 4 and stuck in pagination i have a list of customers and in pagination first page is displaying 10 records properly but when i click page 2 button i get error message "The requested URL was not found on this server." can anyone help me
my controller is
<?php
namespace App\Controllers;
use App\Models\CustModel;
class Main extends BaseController
{
protected $request;
public function __construct()
{
$this->request = \Config\Services::request();
$this->session = session();
$this->cust_model = new CustModel;
$this->data = ['session' => $this->session,'request'=>$this->request];
}
public function index()
{
$this->data['page_title']="Home";
return view('pages/home', $this->data);
}
public function customers(){
$this->data['page_title']="customers";
$this->data['page'] = !empty($this->request->getVar('page')) ? $this->request->getVar('page') : 1;
$this->data['perPage'] = 10;
$this->data['total'] = $this->cust_model->countAllResults();
$this->data['customers'] = $this->cust_model->paginate($this->data['perPage']);
$this->data['total_res'] = is_array($this->data['customers'])? count($this->data['customers']) : 0;
$this->data['pager'] = $this->cust_model->pager;
return view('pages/customers/list', $this->data);
}
}
my model is
<?php
namespace App\Models;
use CodeIgniter\Model;
class CustModel extends Model{
protected $DBGroup = 'default';
protected $table = 'customer';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $insertID = 0;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['name','fname','password', 'cnic','phone','age', 'gender', 'address'];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
my list page is
<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<div class="card rounded-0">
<div class="card-header">
<div class="d-flex w-100 justify-content-between">
<div class="col-auto">
<div class="card-title h4 mb-0 fw-bolder">List of customers</div>
</div>
<div class="col-auto">
<a href="<?= base_url('Main/user_add') ?>" class="btn btn btn-primary bg-gradient
border rounded-0"><i class="far fa-plus-square"></i> Add customer</a>
</div>
</div>
</div>
<div class="card-body">
<div class="container-fluid">
<table class="table table-striped table-bordered">
<thead>
<th class="p-1 text-center">id</th>
<th class="p-1 text-center">Name</th>
<th class="p-1 text-center">fname</th>
<th class="p-1 text-center">cnic</th>
<th class="p-1 text-center">phone</th>
<th class="p-1 text-center">gender</th>
<th class="p-1 text-center">age</th>
<th class="p-1 text-center">address</th>
<th class="p-1 text-center">Action</th>
</thead>
<tbody>
<?php foreach($customers as $row): ?>
<tr>
<th class="p-1 text-center align-middle"><?= $row['id'] ?></th>
<td class="px-2 py-1 align-middle"><?= $row['name'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['fname'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['cnic'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['phone'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['gender'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['age'] ?></td>
<td class="px-2 py-1 align-middle"><?= $row['address'] ?></td>
<td class="px-2 py-1 align-middle text-center">
<i class="fa fa-edit"></i>
<i class="fa fa-trash"></i>
</td>
</tr>
<?php endforeach; ?>
<?php if(count($customers) <= 0): ?>
<tr>
<td class="p-1 text-center" colspan="4">No result found</td>
</tr>
<?php endif ?>
</tbody>
</table>
<div>
<?= $pager->makeLinks($page, $perPage, $total, 'custom_view') ?>
</div>
</div>
</div>
</div>
<?= $this->endSection() ?>
my custom view is
<!-- Limit to 3 Links each side of the current page -->
<?php $pager->setSurroundCount(3) ?>
<!-- END-->
<div class="row">
<!-- Pagination -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<ul class="pagination">
<!-- Previous and First Links if available -->
<?php if($pager->hasPrevious()): ?>
<li class="page-item">
First
</li>
<li class="page-item">
Previous
</li>
<?php endif; ?>
<!-- End of Previous and First -->
<!-- Page Links -->
<?php foreach($pager->links() as $link): ?>
<li class="page-item <?= $link['active'] ? 'active' : '' ?>"><a class="page-link"
href="<?= $link['uri'] ?>"><?= $link['title'] ?></a></li>
<?php endforeach; ?>
<!-- End of Page Links -->
<!-- Next and Last Page -->
<?php if($pager->hasNext()): ?>
<li class="page-item">
Next
</li>
<li class="page-item">
Last
</li>
<?php endif; ?>
<!-- End of Next and Last Page -->
</ul>
</div>
<!-- End of Pagination -->
<!-- Pagination Details -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<?php if($total_res > 0): ?>
<div class="fw-light fs-italic text-muted text-end">Showing <?= (($page * $perPage) -
$perPage +1) ."-". (($page * $perPage) - $perPage + ($total_res)) ?> Result out of <?=
number_format($total) ?></div>
<?php endif; ?>
</div>
<!-- End of Pagination Details -->
</div>
my routs are
$routes->get('/', 'Dashbord::index');
$routes->get('/loadlog', 'Dashbord::loadlog');
$routes->match(['post'], '/login', 'Dashbord::loadlog');
$routes->group('/Main', ['filter'=>'authented'], static function($routes){
$routes->get('', 'Main::index');
$routes->get('(:segment)', 'Main::$1');
$routes->get('(:segment)/(:any)', 'Main::$1/$2');
$routes->match(["get", "post"], "edit-customer/(:num)", "Customer::editCustomer/$1");
});
actually there was an error in my base url i was using public folder of codeigniter 4 but i was not including it in my base url initially i used base url http://localhost/plab/ but now i changed to http://localhost/plab/public/ after this now i am getting all pages
Related
I have created a table called jeniskerja which contains the category (id's range from 1-5) of the pekerjaan's table. I already made the eloquent model for each of the said table;
jeniskerja (model)
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Jeniskerja extends Eloquent
{
use HasFactory;
protected $guarded = [];
public $timestamps = false;
public function pekerjaans(){
return $this->hasMany(Pekerjaan::class);
}
}
pekerjaan (model)
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Pekerjaan extends Eloquent
{
use HasFactory;
protected $guarded = [];
protected $dates = ['tanggal'];
public function penyedia(){
return $this->belongsTo(Penyedia::class, 'penyedia_id');
}
public function jeniskerja(){
return $this->belongsTo(Jeniskerja::class, 'jeniskerja_id');
}
public function user(){
return $this->belongsTo(User::class, 'user_id');
}
}
At the moment, when the user click on the vendor's name, it will direct them to show a detail of the vendor and the table list of work... What I need is to show the table based on the category id when the user click on the said category tab... Here is the picture to show the page
And here is my code to view the page:
<section class="content">
<div class="container-fluid">
<div class="card card-default color-palette-box">
<div class="card-header">
<h3 class="card-title">
<b>{{$penyedia->nama}}</b>
</h3>
</div>
<div class="card-body">
<div class="col-12">
<h5><i class="fas fa-id-card"></i>  NPWP: {{$penyedia->npwp}}</h5><br>
<h5><i class="fas fa-map-pin"></i>  Alamat: {{$penyedia->alamat}}</h5>
</div>
</div>
<hr class="solid" style="border-top: 1px solid;">
<div class="card-body">
<div class="col-12">
<h5><i class="fas fa-building"></i>  Bentuk Usaha: {{$penyedia->bentuk_usaha}}</h5><br>
<h5><i class="fas fa-envelope"></i>  Email: {{$penyedia->email}}</h5>
</div>
</div>
</div>
</div>
</section>
<section class="content">
<div class="container-fluid">
<!-- Small boxes (Stat box) -->
#foreach ($penyedia as $penyedias)
#endforeach
<div class="row">
{{-- <div class="col-lg-4 col-6">
<!-- small card -->
<div class="small-box bg-info">
<div class="inner">
<h3>{{$penyedia->count('nama')}}</h3>
<p>Penyedia</p>
</div>
<div class="icon">
<i class="fas fa-store"></i>
</div>
<a href="/datapenyedia" class="small-box-footer">
More info <i class="fas fa-arrow-circle-right"></i>
</a>
</div>
</div> --}}
<!-- ./col -->
<div class="col-lg-6 col-8">
<!-- small box -->
<div class="small-box bg-lightblue">
<div class="inner">
<h3>{{$pekerjaan->count('pekerjaan')}}</h3>
<p>Pekerjaan</p>
</div>
<div class="icon">
<i class="fas fa-map"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
<div class="col-lg-6 col-8">
<!-- small box -->
<div class="small-box bg-lightblue">
<div class="inner">
<h3>Rp. {{number_format($pekerjaan->sum('nilai_kontrak'))}}</h3>
<p>Nilai Kontrak</p>
</div>
<div class="icon">
<i class="fas fa-money-bill-wave"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
</div>
</div>
</section>
#foreach ($jeniskerja as $jeniskerjas)
<section class="content">
<div class="container-fluid">
<div class="card card-default collapsed-card">
<div class="card-header collapsed-card">
<h3 class="card-title">
<b>{{$jeniskerjas->nama_jenis}}</b>
</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px" rowspan="2">Tahun Anggaran</th>
<th rowspan="2">Tanggal Kontrak</th>
<th rowspan="2">Paket Pekerjaan</th>
<th rowspan="2">Nama Perusahaan</th>
<th rowspan="2">Lokasi Pekerjaan</th>
<th rowspan="2">Jenis Pekerjaan</th>
<th rowspan="2">HPS</th>
<th rowspan="2">Nilai</th>
<th rowspan="2">Dokumen</th>
<th colspan="2">Tanggal</th>
</tr>
<tr>
<td>Tgl Buat</td>
<td>Tgl Update</td>
</tr>
</thead>
<tbody>
#php $no = 1; /*$totalNilai = 0.0;*/ #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$pekerjaans->tanggal->format('Y')}}</td>
<td>{{$pekerjaans->tanggal->format('d/m/Y')}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->jeniskerja->nama_jenis}}</td>
<td>Rp. {{number_format($pekerjaans->hps,0,',',',')}}</td>
#php
$pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
#endphp
<td>{{$pekerjaans->nilai_total}}</td>
<td><u>{{$pekerjaans->status}}</u></td>
<td>
</td>
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</section>
#endforeach
And here is the AdminController file
public function showpenyedia(Penyedia $penyedia){
$pekerjaan = $penyedia->pekerjaans; //show pekerjaan(work) based on penyedia(vendor)
$jeniskerja = Jeniskerja::all();
return view('admin.showpenyedia', compact('penyedia','pekerjaan','jeniskerja'));
}
<?php
include('includes/db.php');
?>
<?php include('functions/functions.php'); ?>
<?php
include('header.php');
?>
<?php
include('topheader.php');
?>
<?php
include('nav.php');
?>
<div id="content">
<div class="container">
<div class="col-md-12">
<ul class="breadcrumb">
<li>Home</li>
<li>Cart</li>
</ul> <!--breadcrumb ends--->
</div> <!---col-md-12 ends-->
<div class="col-md-9" id="cart">
<div class="box">
<form action="cart.php" method="post" enctype="multipart-form-data">
<h1>Shopping Cart</h1>
<?php
$ip_add = getUserIP();
$select_cart = "select * from cart where ip_add='$ip_add'";
$run_cart = mysqli_query($conn, $select_cart);
$count = mysqli_num_rows($run_cart);
?>
<p class="text-muted">You currently have <?php echo $count; ?> items in your cart</p>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th colspan="2">Product</th>
<th>Quantity</th>
<th colspan="1">Unit Price</th>
<th>Container</th>
<th colspan="1">Delete</th>
<th colspan="2">Sub Total</th>
</tr>
</thead> <!--thead ends-->
<tbody>
<?php
$total = 0;
while ($row_cart = mysqli_fetch_array($run_cart)) {
$pro_id = $row_cart['p_id'];
$pro_size = $row_cart['size'];
$pro_qty = $row_cart['qty'];
$get_products = "select * from products where product_id='$pro_id'";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_array($run_products)) {
$product_title = $row_products['product_title'];
$product_img1 = $row_products['product_img1'];
$only_price = $row_products['product_price'];
$sub_total = $row_products['product_price'] * $pro_qty;
$total += $sub_total;
}
?>
<tr>
<td><img src="admin_area/product_images/<?php echo $product_img1; ?>"></td>
<td><?php echo $product_title; ?></td>
<td><?php echo $pro_qty; ?></td>
<td>₹<?php echo $only_price; ?>.00</td>
<td><?php echo $pro_size ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?>"></td>
<td>₹<?php echo $sub_total; ?>.00</td>
</tr> <!---tr ends-->
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th colspan="2">₹ <?php echo $total; ?>.00</th>
</tr>
</tfoot> <!--tfoot ends-->
</table> <!--table ends-->
</div> <!---table-responsive end-->
<div class="box-footer">
<div class="pull-left">
<a href="index.php" class="btn btn-default">
<i class="fa fa-chevron-left"></i>Continue Shopping
</a>
</div> <!--pullleft ends-->
<div class="pull-right">
<button class="btn btn-default" type="submit" name="update" value="Update Cart"><i class="fa fa-refresh"></i>Update Cart </button>
<a href="checkout.php" class="btn btn-primary">
Proceed to checkout<i class="fa fa-chevron-right"></i>
</a>
</div> <!--pullright ends-->
</div> <!----box footer ends-->
</form> <!---form ends-->
</div> <!---box ends-->
<?php
function update_cart() {
global $conn;
if (isset($_POST['update'])) {
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "delete from cart where p_id='$remove_id'";
$run_delete = mysqli_query($conn, $delete_product);
if ($run_delete) {
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
}
echo #$up_cart = update_cart();
?>
<div class="row same-height-row">
<div class="col-md-3 col-md-6">
<div class="box same-height headline">
<h3 class="text-center">Recently Viewed Product</h3>
</div> <!----box same-height headline end-->
</div> <!---col-m-3 col-md-6 ends---->
<?php
$get_products = "select * from products order by rand() LIMIT 0,3";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_assoc($run_products)) {
$pro_id = $row_products['product_id'];
$pro_title = $row_products['product_title'];
$pro_price = $row_products['product_price'];
$pro_img1 = $row_products['product_img1'];
echo "<div class='center-responsive col-md-3 col-sm-6'>
<div class='product same-height'>
<a href='details.php?pro_id=$pro_id'>
<img src='admin_area/product_images/$pro_img1' class='img-responsive'>
</a>
<div class='text'>
<h3><a href='details.php?pro_id=$pro_id'>$pro_title</a></h3>
<p class='price'>₹ $pro_price</p>
</div>
</div>
</div>";
}
?>
</div>
</div>
<div class="col-md-3">
<div class="box" id="order-summary">
<div class="box-header">
<h3>Order Summary</h3>
</div> <!--box-header ends-->
<p class="text-muted">
Shipping and additional costs are calulated based on the value you have entered.
</p>
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>Order Subtotal</td>
<th>₹<?php echo $sub_total; ?></th>
</tr>
<tr>
<td>Shipping and Handling</td>
<td>₹0.00</td>
</tr>
<tr>
<td>Tax</td>
<td>₹0.00</td>
</tr>
<tr class="total">
<td>Total</td>
<th>₹ <?php echo $total; ?></th>
</tr>
</tbody>
</table> <!--table ends-->
</div> <!---table responsive ends-->
</div> <!---box ends-->
</div> <!----col-md-3 ends--->
</div> <!--container ends-->
</div> <!---content ends-->
<?php include_once 'footer.php'; ?>
i get undefined variable sub_total even after defining variable subtotal above. Can someone figure out what the problem is?? I have check all curly brackets and semicolen. Due on a project that needs to be submited tomorrow. I am thinking improving the coding later but the basic functionality is not working.
I am new to PHP and also C.I, I am creating a Search Filter, The filter is working properly until i moved to the next Pagination link. When i am on First link the data is showing according to the filter/search keyword, but as i move to the next link everything goes off (All the data shows on page).
I searched a lot and go through many links/tutorials but did not find authentic/proper/specific answer for such issue.
I find a Link here on Stack Overflow and follow it, but got no LUCK.
My Controller Code:
public function URecords() {
$config = array();
$keyword = $this->input->post('search');
$this->session->set_flashdata('search',$keyword);
$config["base_url"] = base_url() . "master/URecords";
$config["total_rows"] = $this->bm->record_count($keyword);
$config['use_page_numbers'] =FALSE;
$config['cur_tag_open'] = '<a><b class="text-success">';
$config['cur_tag_close'] = '</b></a>';
$config["per_page"] =4;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["posts"] = $this->bm->fetch_countries($config["per_page"], $page,$keyword);
$data["links"] = $this->pagination->create_links();
$this->load->view('Admin/header');
$this->load->view('Admin/nav');
$this->load->view('Admin/sidebar');
$this->load->view('Admin/userrecord', $data);
$this->load->view('Admin/footer');
}
My Model Code:
public function record_count($keyword) {
$this->db->like('Employee_Name',$keyword);
$this->db->from('dc_user');
return $this->db->count_all_results();
// return $this->db->count_all("dc_user");
}
public function fetch_countries($limit, $start,$keyword) {
$this->db->limit($limit, $start);
$this->db->like('Employee_Name',$keyword);
$query = $this->db->get_where("dc_user");
if(empty($query->result()))
{
//echo "No record found in data base";
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">No Record Found!</div>');
}
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
My View Code:
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
<form action="<?php echo base_url();?>Master/URecords" method="post">
<div class="input-group">
<input type="text" class="form-control" id="search" name="search" value="<?php if(isset($_SESSION['search'])){echo $_SESSION['search'];}?>" placeholder="Search for...">
<span class="input-group-btn">
<input class="btn btn-default" type="submit" name="submit" id="submit" value="GO!">
</span>
</div>
</form>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>All User's Record</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
</li>
<li class="dropdown">
<i class="fa fa-wrench"></i>
<ul class="dropdown-menu" role="menu">
<li>Settings 1
</li>
<li>Settings 2
</li>
</ul>
</li>
<li><a class="close-link"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="table-responsive">
<?php if(isset($_SESSION['msg'])){?>
<span class="text-info col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<?php echo $this->session->flashdata('msg'); ?>
</span>
<?php } else {?>
<table class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Employee Name </th>
<th class="column-title">Email </th>
<th class="column-title">Contact # </th>
<th class="column-title">Date Of Birth </th>
<th class="column-title">Designation </th>
<th class="column-title">Profile Picture </th>
</tr>
</thead>
<tbody>
<?php foreach($posts as $post) { ?>
<tr class="even pointer">
<td class=" "><?php echo $post->Employee_Name; ?></td>
<td class=" "><span class="text-info"><?php echo $post->Email; ?></span></td>
<td class=" "><?php echo $post->Contact; ?></td>
<td class=" "><?php echo $post->DOB; ?></td>
<td class=" "><?php echo $post->Designation; ?></td>
<td class=" "><img src="<?php echo base_url();?>profileimages/<?php echo $post->Profile_Image; ?>" alt="..." class="img-square profile_img" style="width: 200px !important; height: 100px !important;"> </td>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="text-center"><nav aria-label="Page navigation">
<ul class="pagination">
<li><?php echo $links; ?></li>
</ul>
</nav></div>
<?php }?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Main Issue:
The Issue is: When i enter any keyword in search field then it will show the correct result on start but as i move to the other pagination links then i lose the search result.
What I Want:
When I Go through Pagination links then it will works as it work on Start of Search.
the problem is you did not retrieve the keyword when navigate through pagination links.
pagination is a regular <a> so it is not sending any POST data
replace this line:
$keyword = $this->input->post('search');
$this->session->set_flashdata('search',$keyword);
with this:
$keyword = $this->input->post('search');
if ($keyword === null) $keyword = $this->session->userdata('search');
else $this->session->set_userdata('search',$keyword);
this code save the keyword into session, and check if the keyword is not provided by POST then retrieve the keyword from session
I have built a page with CodeIgniter, that has a search function and a datatable.
Whenever I click the search button, the datatable will change accordingly to the parameter submitted. But it not working as I expected.
This is My Model
public function ocsmodel($biostype=null, $manufacture=null)
{
// Loading second db and running query.
if ($biostype==null and $manufacture == Null) {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->limit(100)
->get();
}
else {
if ($manufacture == "") {
}
else {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->where('bios_type',$biostype)
->where('smanufature',$manufacture)
->limit(100)
->get();
}
}
}
This is my controller
public function ocslist()
{
$manufactur ="";
$biostype ="";
if (isset($_POST['bios_type'])){
$biostype = $this->input->post('bios_type');
if (isset($_POST['manufacture'])){
$manufactur = $this->input->post('manufacture');
}
$data['ocs'] = $this->assetmodel->ocsmodel()->result_array();
}
else {
$data['ocs'] = $this->assetmodel->ocsmodel($biostype,$manufactur)->result_array();
}
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
And This is My View
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<!--<div class="title_left">
<h3>
Master Department
<small>
List
</small>
</h3>
</div> -->
</div>
<div class="clearfix"></div>
<div class = "row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>OCS INVENTORY LIST</h2>
<ul class="nav navbar-right panel_toolbox">
<li><i class="fa fa-chevron-up"></i>
</li>
<li class="dropdown">
<i class="fa fa-wrench"></i>
</li>
<li><i class="fa fa-close"></i>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="x_content">
<!-- search parameters -->
<form class="form-default" method="POST" action="<? echo base_url('asset/ocslist'); ?>">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="bios_type">Type <span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="select2_single form-control" tabindex="-1" name="bios_type">
<?php foreach ($ocstype as $key => $value) { ?>
<option value="<? echo $value['bios_type']?>"><? echo $value['bios_type']?></option>}
<? } ?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="manufacture">Manufacture </label>
<div class="col-md-3">
<select class="select2_single form-control" tabindex="1" name="manufacture">
<?php foreach ($ocsmanu as $key => $value) { ?>
<option value="<? echo $value['smanufacturer']?>"><? echo $value['smanufacturer']?></option>}
<? } ?>
</select>
</div>
</div>
<div>
<button type="button" class="btn btn-info" name="submit">Search</button>
Master Asset
</div>
</div>
</form>
<table id="datatable-fixed-header" class="table responsive-utilities table-bordered">
<thead>
<tr>
<th>Type</th>
<th>Device ID</th>
<th>Manufacture</th>
<th>Model</th>
<th>Nama</th>
<<th>User ID</th>
<th>Mac_Address</th>
<th>Serial Number</th>
<th>Asset</th>
</tr>
</thead>
<tbody>
<?php foreach ($ocs as $key => $value) { ?>
<tr>
<td><?php echo $value['bios_type'];?> </td>
<td><?php echo $value['DEVICEID'];?> </td>
<td><?php echo $value['SMANUFACTURER'];?> </td>
<td><?php echo $value['smodel'];?> </td>
<td><?php echo $value['name'];?> </td>
<td><?php echo $value['userid'];?> </td>
<td><?php echo $value['macaddr'];?> </td>
<td><?php echo $value['SSN'];?> </td>
<td>Add Asset</td>
</tr>
<? } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
what about changing your controller into something like
public function ocslist()
{
$data['ocs'] = $this->assetmodel->ocsmodel($this->input->post('bios_type'), $this->input->post('manufacture'))->result_array();
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
because CI sets all POST Data to null if they doesn't exist
For more information look here
Update (20.07.2016)
according to your view try to change the button type into something like this
<button type="submit" class="btn btn-info" name="submit">Search</button>
I want to put quick filters to my tables. So there needs to be a number of dropdowns to help filter the results quickly relating to each of my tables. How could I do it?
This is my view file:
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header" data-original-title>
<div class="box-icon">
<i class="halflings-icon wrench"></i>
<i class="halflings-icon chevron-up"></i>
<i class="halflings-icon remove"></i>
</div>
</div>
<div class="box-content">
<table id="segment" class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>UNSPSC SEGMENT</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<?php foreach($dash_present_all_selected_suppliers as $v): ?>
<tr>
<td class="center" style="color:#0c595b;"><?php echo $v->name;?> </td>
<td class="center">70%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/
and that is my controller:
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('dash_match_model');
$this->load->library('session');
$this->load->helper('url');
}
public function index() {
$arr['page']='dash1';
$user_id = $this->session->userdata('id');
$supplier = $this->dash_match_model->dash_present_all_suppliers($user_id);
$arr['dash_present_all_suppliers'] = $supplier;
$this->load->view('clients/clDashboard',$arr);
}
public function select_supplier()
{
$supplier_name = $this->input->get('name', TRUE);
$supplier_id="";
$supplier_sel = $this->dash_match_model->selected_supplier_id($supplier_name);
foreach ($supplier_sel->result() as $row){
$supplier_id = $row->supplier_id;
}
$selected_supplier = $this->dash_match_model->unspsc_matched_skus($supplier_id);
$arr['dash_present_all_selected_suppliers'] = $selected_supplier;
$this->load->view('clients/unspscSegment', $arr);
}