Server side multiple datables showing multiple paginations and search boxes - php

I have two tables in single page with same class and the data for generated tables are server side processed.
Take a look at the below code.
PHP code
<table class="table table-striped display" id="somedetailList" >
<thead>
<tr>
<th>some Name</th>
<th>some Adress</th>
<th>some Mobile</th>
<th>some Name</th>
<th>some da</th>
<th>some as</th>
<th>some ds</th>
</tr>
</thead>
<tbody>
<?php foreach ($ros as $row) { ?>
<tr>
<td><?php echo $row->partyname; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->phonenumber; ?></td>
<td><?php echo $row->name ?></td>
<td><?php echo $row->total; ?></td>
<td><?php echo $row->advance; ?></td>
<td><?php echo $row->balance; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<table class="table table-striped display" id="vehicledetailList" >
<thead>
<tr>
<th>Party Name</th>
<th>Party Adress</th>
<th>Party Mobile</th>
<th>Driver Name</th>
<th>Total</th>
<th>Advance</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
<?php foreach ($balan as $bal) { ?>
<tr>
<td><?php echo $bal->partyname; ?></td>
<td><?php echo $bal->address; ?></td>
<td><?php echo $bal->phonenumber; ?></td>
<td><?php echo $bal->name ?></td>
<td><?php echo $bal->total; ?></td>
<td><?php echo $bal->advance; ?></td>
<td><?php echo $bal->balance; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
And Script for tables is below
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<script>
jQuery(document).ready(function(){
jQuery('table.display').DataTable();
});
</script>
http://jsfiddle.net/qdRDw/
Even i tried exactly as this fiddle, then too iam getting the same issue, i'm getting multiple pagination box for each tables.
Please help.

Modified the sDOM variable in this updated JSFiddle: http://jsfiddle.net/qdRDw/64/
Is this what you wanted?

Related

Php automatic time countdown(timer) as soon as a record is inserted

I have a table for saving details including logging time.Just as soon as a new record is inserted I want the column 'Countdown' to start an automatic time countdown from 30min until it gets to zero(0).How do I go about it?Thanks.
Here is the table php code
`<?php $results = mysqli_query($db, "SELECT
Vehicle_name,Vehicle_make,Vehicle_color,Number_plate,Date,Time FROM
vehicle"); ?>
<div class="table">
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle color</th>
<th>Reg Number</th>
<th>Date</th>
<th>Time</th>
<th>Countdown</th>
<th colspan="4">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['Vehicle_name']; ?></td>
<td><?php echo $row['Vehicle_make']; ?></td>
<td><?php echo $row['Vehicle_color']; ?></td>
<td><?php echo $row['Number_plate']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td>
<a href="php_code.php?del=<?php echo $row['Number_plate']; ?>"
class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
`

Display php data in a html table using while loop

Each time i echo out information from the database using while loop, the first results are displayed in only one row while the rest of the results are printed outside the table as raw text.
<table class="table table-striped">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()):
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td>Update Order</td>
<td>Delete</td>
</tr>
</tbody>
</table>
<?php endwhile; }else
echo "<div class='btn bg-danger'>search not found</div>";
?>
Guys,only the first result is displayed proparly in the table, i want all the data display inside the table.
You are closing the table inside the loop. It's important that you keep the row only in the while.
Then be careful to close all brackets correctly.
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()){
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td>Update Order</td>
<td>Delete</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
if($sql->num_rows == 0){
echo "<div class='btn bg-danger'>search not found</div>";
}
?>

adding inline CSS in datatable row on condition not working

I tried to highlight records whose certain columns have some values other than NULL. I'm using dataTable plugin.
<table class="table table-striped table-hover" id="checkin-checkout-record-table">
<thead>
<tr>
<th>Employee Name</th>
<th>Check-in-date</th>
<th>Check-in-time</th>
<th>Check-out-date</th>
<th>Check-out-time</th>
<th class="col-lg-2">Late Check-in Remarks</th>
<th class="col-lg-2">Early Check-out Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checkinCheckoutList as $member): ?>
<tr <?php
if(isset($member['early_checkout_remarks']) ||isset($member['delayed_checkin_remarks']))
{?>
style="background-color:red;"
<?php } ?> >
<td><?php echo $member['fullname'] ?></td>
<td> <?php echo $member['checkin_date']; ?></td>
<td> <?php echo $member['checkin_time']; ?></td>
<td><?php echo $member['checkout_date']; ?></td>
<td><?php echo $member['checkout_time']; ?></td>
<td><?php echo $member['delayed_checkin_remarks']; ?></td>
<td><?php echo $member['early_checkout_remarks']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
But the result is not as expected. Some records are not highlighted. This works well with other normal table. Please help.

Display the rows from query in table

I have this code to get all the data from my products table. It's working great like this:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['id'];
echo $row['country'];
echo $row['price'];
echo $row['games'];
echo $row['plus'];
echo $row['buylink'];
echo "<br/>";
}
But I want these results to be shown in a table inside the body. I tried something but it's not working.
This is how the table looks :
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
</tbody>
<?php
if ($result->num_rows > 0) {
?>
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
<?php }?>
</tbody>
</table>
<?php
}else {
// if there is no result... Code something here.
}
?>
Youre getting close. You need to have the loop spit out the rows into the html.
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetch_row()) {
echo "<tr>";
foreach ($row as $item) {
echo "<td>$item</td>";
}
echo"</tr>";
}
?>
</tbody>
also instead of using a associative array and indexing into it (ie. $row['country']), You can use a normal array and a foreach loop to cut down on the code.
LE:
Each html table row is created based on each database's table row. So, you just need to loop through the result set (that while), and for each iteration of the loop, you need to create a new html table row:
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Games</th>
<th>Plus</th>
<th>Buy Link</th>
</tr>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['games']; ?></td>
<td><?php echo $row['plus']; ?></td>
<td><?php echo $row['buylink']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

How to avoid displaying duplicated values or overwrite duplicated values in php foreach loop in table?

I'm currently working on codeigniter. I want to display a value that is not been duplicated or overwrite a duplicated value from mysql database into the datatable of php foreach loop.
Here is the table code:
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee No.</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
foreach($EMPLOYEES as $employee){?>
<tr>
<td><?php echo $employee->empnum; ?></td>
<td><?php echo $employee->username; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php
if ($employee->hasClockOut==1){
echo '<a class="label label-danger">Inactive</a>';
}else {
echo '<a class="label label-success">Active</a>';
}
?></td>
</tr>
<?php } ?>
</tbody>
</table>
Why not just use -
$EMPLOYEES = array_unique($EMPLOYEES);
Try this
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee No.</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php $emp='';
foreach($EMPLOYEES as $employee){
if($emp!=$employee->username){ # if username contain duplicate values
?>
<tr>
<td><?php echo $employee->empnum; ?></td>
<td><?php echo $employee->username; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php
if ($employee->hasClockOut==1){
echo '<a class="label label-danger">Inactive</a>';
}else {
echo '<a class="label label-success">Active</a>';
}
?></td>
</tr>
<?php }$emp=$employee->username;} ?>
</tbody>
</table>

Categories