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>
Related
I have some edit modal and i want it to show the detail of DATA in bootsrap modal based on ID. Here is my index code:
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
And here is my modal :
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $user['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $user['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $user['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u) : ?>
<option value="<?= $u['id']; ?>"><?= $u['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
For now It shows the data based on ID, but when i try to click edit button of another data, it show the same detail of one ID only.
I hope that every i click every data button, it shows different detail based on id. I've check similar case already but no one of them that work on my code. I just know my code need some jquery, but i just new on it.
like saad said, place it inside the loop
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal<?=$i?>">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal<?=$i?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $u['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $u['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $u['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u2) : ?>
<option value="<?= $u2['id']; ?>"><?= $u2['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
Basically my modal is inside my div, but i want it outside of it... the problem is i am making use of a foreach statement aswell so it needs to be inside the foreach statement but also outside of the content div.
Here's my code:
<div class="content">
<div class="block block-rounded block-fx-pop block-themed">
<div class="block-header bg-gd-sublime">
<h3 class="block-title">Manage subscription plans</h3>
</div>
<div class="block-content block-content-full">
<!-- DataTables init on table by adding .js-dataTable-full class, functionality is initialized in js/pages/be_tables_datatables.min.js which was auto compiled from _es6/pages/be_tables_datatables.js -->
<table class="table js-dataTable-full">
<tbody>
<tr>
<th style="font-size: 12px;">Subscription name</th>
<th class="text-center" style="font-size: 12px;">Color</th>
<th class="text-center" style="font-size: 12px;">Price</th>
<th class="text-center" style="font-size: 12px;">duration</th>
<th class="text-center" style="font-size: 12px;">Account/day</th>
<th class="text-center" style="font-size: 12px;">Accounts type</th>
<th class="text-center" style="font-size: 12px;">Private</th>
<th class="text-center" style="font-size: 12px;">Users</th>
</tr>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<tr>
<td style="font-size: 12px;">
<a class="link-fx" href="#" data-toggle="modal" data-target="#exampleModalCenter<?php echo $id; ?>"><?=$dPlans['name']?></a>
</td>
<td class="text-center" style="font-size: 12px;"><i class="fa fa-circle" style='color:<?=$dPlans['color']?>'></i></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['price']?> €</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['length']?> <?=$dPlans['unit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['limit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['accounts']?></td>
<td class="text-center" style="font-size: 12px;"><?=$private?></td>
<td class="text-center" style="font-size: 12px;"><?=$people?></td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit Plan: <?=$dPlans['name']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post">
<div class="block-content">
<div class="row items-push">
<div class="col-lg-12">
<div class="form-group">
<label for="val-username">Name</label>
<input type="text" class="form-control" id="name2" name="name<?php echo $id; ?>" value="<?=$dPlans['name']?>">
</div>
<div class="form-group">
<label for="val-email">Price</label>
<input type="text" class="form-control" id="price2" name="price<?php echo $id; ?>" value="<?=$dPlans['price']?>">
</div>
<div class="form-group">
<label for="val-password">Duration</label>
<input type="text" class="form-control" id="length2" name="length<?php echo $id; ?>" value="<?=$dPlans['length']?>">
</div>
<div class="form-group">
<label for="val-skill">Time unit <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="unit<?php echo $id; ?>">
<option value="Days" <?php echo selectedUnit('Days',$dPlans['unit']); ?>>Days</option>
<option value="Weeks" <?php echo selectedUnit('Weeks',$dPlans['unit']); ?> >Week</option>
<option value="Months" <?php echo selectedUnit('Months',$dPlans['unit']); ?>>Month</option>
<option value="Years" <?php echo selectedUnit('Years',$dPlans['unit']); ?>>Year</option>
</select>
</div>
<div class="form-group">
<label for="val-password">Account per day</label>
<input type="text" class="form-control" id="length2" name="limit<?php echo $id; ?>" value="<?=$dPlans['limit']?>">
</div>
<div class="form-group">
<label for="val-password">Account type</label>
<input type="text" class="form-control" id="length2" name="accounts<?php echo $id; ?>" value="<?=$dPlans['accounts']?>">
</div>
<div class="form-group">
<label for="val-skill">Private <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="private<?php echo $id; ?>">
<option value="1" <?php echo selectedUnit(1,$dPlans['private']); ?>>Yes</option>
<option value="0" <?php echo selectedUnit(0,$dPlans['private']); ?>>No</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button name="update" value="<?php echo $id; ?>" class="btn btn-primary" type="submit">Update</button>
</div>
</div>
</div>
</div>
<?php }
?>
</tbody>
</table>
</div>
</div>
I've tried moving/adding divs but no change and it still displays like this:
I know my formating is really bad.
What Yasir Suggested me to do:
<div class="content">
<div class="block block-rounded block-fx-pop block-themed">
<div class="block-header bg-gd-sublime">
<h3 class="block-title">Manage subscription plans</h3>
</div>
<div class="block-content block-content-full">
<!-- DataTables init on table by adding .js-dataTable-full class, functionality is initialized in js/pages/be_tables_datatables.min.js which was auto compiled from _es6/pages/be_tables_datatables.js -->
<table class="table js-dataTable-full">
<tbody>
<tr>
<th style="font-size: 12px;">Subscription name</th>
<th class="text-center" style="font-size: 12px;">Price</th>
<th class="text-center" style="font-size: 12px;">Duration</th>
<th class="text-center" style="font-size: 12px;">Account/day</th>
<th class="text-center" style="font-size: 12px;">Accounts type</th>
<th class="text-center" style="font-size: 12px;">Users</th>
</tr>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<tr>
<td style="font-size: 12px;">
<a class="link-fx" href="#" data-toggle="modal" data-target="#exampleModalCenter<?php echo $id; ?>"><?=$dPlans['name']?></a>
</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['price']?> €</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['length']?> <?=$dPlans['unit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['limit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['accounts']?></td>
<td class="text-center" style="font-size: 12px;"><?=$people?></td>
</tr>
<?php }
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit Plan: <?=$dPlans['name']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post">
<div class="block-content">
<div class="row items-push">
<div class="col-lg-12">
<div class="form-group">
<label for="val-username">Name</label>
<input type="text" class="form-control" id="name2" name="name<?php echo $id; ?>" value="<?=$dPlans['name']?>">
</div>
<div class="form-group">
<label for="val-email">Price</label>
<input type="text" class="form-control" id="price2" name="price<?php echo $id; ?>" value="<?=$dPlans['price']?>">
</div>
<div class="form-group">
<label for="val-password">Duration</label>
<input type="text" class="form-control" id="length2" name="length<?php echo $id; ?>" value="<?=$dPlans['length']?>">
</div>
<div class="form-group">
<label for="val-skill">Time unit <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="unit<?php echo $id; ?>">
<option value="Days" <?php echo selectedUnit('Days',$dPlans['unit']); ?>>Days</option>
<option value="Weeks" <?php echo selectedUnit('Weeks',$dPlans['unit']); ?> >Week</option>
<option value="Months" <?php echo selectedUnit('Months',$dPlans['unit']); ?>>Month</option>
<option value="Years" <?php echo selectedUnit('Years',$dPlans['unit']); ?>>Year</option>
</select>
</div>
<div class="form-group">
<label for="val-password">Account per day</label>
<input type="text" class="form-control" id="length2" name="limit<?php echo $id; ?>" value="<?=$dPlans['limit']?>">
</div>
<div class="form-group">
<label for="val-password">Account type</label>
<input type="text" class="form-control" id="length2" name="accounts<?php echo $id; ?>" value="<?=$dPlans['accounts']?>">
</div>
<div class="form-group">
<label for="val-skill">Private <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="private<?php echo $id; ?>">
<option value="1" <?php echo selectedUnit(1,$dPlans['private']); ?>>Yes</option>
<option value="0" <?php echo selectedUnit(0,$dPlans['private']); ?>>No</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button name="update" value="<?php echo $id; ?>" class="btn btn-primary" type="submit">Update</button>
</div>
</div>
</div>
</div>
</div>
<?php }
?>
I was set up my index page with pending order,sales and completed order. Each and every minutes that data are changed.so i decided to refresh particular div by jquery and got succeed by changing data dynamically.But issues start on my style.When the div was reloded style of card was distract.I dont know why this happened.
<div class="row" >
<div class="col-xl-3 col-lg-3 col-md-6 col-sm-12 col-12" id="here">
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Total Sales</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><? if($total != '') { echo "Rs: ".$total; } else { echo "Rs: 0";} ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Complted Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $complte." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Pending Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $pending." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-9 col-lg-12 col-md-6 col-sm-12 col-12">
<?
$orderquery = mysqli_query($conn,"SELECT * FROM ordermaster o LEFT JOIN customer c ON o.custid = c.custid WHERE o.status = 'p' AND orderdt = CURRENT_DATE() ");
?>
<div class="card">
<h5 class="card-header">Recent Orders</h5>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table">
<thead class="bg-light">
<tr class="border-0">
<th class="border-0">#</th>
<th class="border-0">Name</th>
<th class="border-0">Phone</th>
<th class="border-0">Address</th>
<th class="border-0">Pincode</th>
<th class="border-0">City</th>
<th class="border-0">Order Time</th>
<th class="border-0">Amount</th>
<th class="border-0">View</th>
</tr>
</thead>
<tbody>
<?
$count = 1;
while($res = mysqli_fetch_array($orderquery))
{
?>
<tr>
<td><?= $count; ?></td>
<td><?= $res['name']; ?> </td>
<td><?= $res['phone']; ?> </td>
<td><?= $res['addr1']."/".$res['addr2']; ?> </td>
<td><?= $res['pincode']; ?> </td>
<td><?= $res['city']; ?> </td>
<td><?= $res['orderdtm']; ?> </td>
<td><?= $res['net']; ?> </td>
<td><button class="btn btn-sm btn-outline-primary" title="View Product" onclick="del('<? echo $res['orderid'];?>')" value="id" data-toggle="modal" data-target="#delete" data-backdrop="static" data-keyboard="false"><i class="fas fa-eye"></i></button></td>
</tr>
<?
$count++;
}
?>
<tr>
<td colspan="9">View Details</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
and my jquery coding to reload div is
$(document).ready(function(){
setInterval(function(){
$("#here").load(window.location.href + " #here" );
}, 3000);
});
whats error going on i cann't understand.image before apply load
image after load
To stop the loop you can use clearInterval()
Jquery replace with this
$(document).ready(function(){
window.setInterval(function(){
$("#here").load(window.location.href + " #here");
}, 3000);
clearInterval()
});
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 can't display my search form where i suspect the problem is due to my not working checkboxes. I click search and it contain any error but blank table. Maybe there are probably some php and sql syntax error that i overlook. fyi the form is display at the same page(checkbox) index.php
index.php
<?php require_once('Connections/conn.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Casado</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/kahwin/index.php">Casado</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
<div class="container text-center">
<div class="page-header">
<div class="container">
<form method="post">
<div class="form-group">
<h3><label for="usr">Carian bajet anda:</label></h3>
<div class= "col-md-12">
<div class=" col-md-4"></div>
<div class=" col-md-4">
<input name="bajet" type="text" class="form-control" id="usr"></div>
</div>
<div class=" col-md-4"></div>
</div><br>
<h3><label for="sel1">Pilih negeri pilihan anda:</label></h3>
<div class= "col-md-12">
<div class=" col-md-4"></div>
<div class=" col-md-4">
<select class="form-control" name="sel">
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Pahang</option>
<option>Perak</option>
<option>Terengganu</option>
<option>Selangor</option>
</select>
</div>
<div class=" col-md-4"></div>
</div><br>
<br>
<h5><label for="check">Senarai Pra-perkahwinan:</label></h5>
<center> <div class="checkbox">
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Jurufoto"><label>Jurufoto</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Butik"><label>Butik</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Hiburan"><label>Hiburan</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Kad Kahwin"><label>Kad Kahwin</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Katering"><label>Katering</label></label>
<br>
</center>
<div class="col-md-4"></div>
<div class="col-md-4">
<button class="btn btn-success btn-sm" name="search">Search <span class="glyphicon glyphicon-search"></span></button><br><br>
</div>
<div class="col-md-4"></div>
</div>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>Jenis</th>
<th>Vendor</th>
<th>Negeri</th>
<th>No.</th>
<th>Pakej</th>
<th>Harga</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$budget = $_POST['bajet'];
$select = $_POST['sel'];
$check = $_POST['check_list'];
if (isset($_POST['search'])) {
mysql_select_db($database_conn, $conn);
$sql = mysql_query(" SELECT *
FROM vendor
RIGHT JOIN item
ON vendor.v_id=item.v_id
WHERE item.harga <= ' $budget '
AND vendor.state = ' $select '
AND vendor.type = ' $check ' );
while($row = mysql_fetch_array($sql)) {
?>
<tr>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['companyName'] ?></td>
<td><?php echo $row['state'] ?></td>
<td><?php echo $row['contact'] ?></td>
<td><?php echo $row['harga'] ?></td>
<td><?php echo $row['pakej'] ?></td>
<td>View Package</td>
</tr>
<?php }
}
?>
</tbody>
</table>
</div>
Use implode() for checkbox to convert into string from array of selected checkbox.
<?php
$budget = $_POST['bajet'];
$select = $_POST['sel'];
$check = implode("','", $_POST['check_list']);
$finalCheck = "'".$check ."'";
if (isset($_POST['search'])) {
mysql_select_db($database_conn, $conn);
$sql = mysql_query(" SELECT *
FROM vendor
RIGHT JOIN item
ON vendor.v_id=item.v_id
WHERE item.harga <= '%". $bajet . "%'
AND vendor.state = '%". $select ."%'
AND vendor.type IN (". $finalCheck ." )" );
?>