image link
Good day everyone i would like to ask if there is someone had a idea on how to make that specific column a link so that the user can download that pdf file.
This my Datatable
<table id="example" class="table table-striped table-bordered table-hover" style="width:100%">
<thead>
<tr>
<th class="text-center align-middle">Control Number</th>
<th class="text-center align-middle">Attached Form</th>
<th class="text-center align-middle">P.R. Date.</th>
<th class="text-center align-middle">ABC/PR Amount.</th>
<th class="text-center align-middle">File</th>
</tr>
</thead>
<tbody>
<?php
if($logs){
foreach ($logs as $log){
?>
<tr>
<td class="<?php
if (empty($log->control_number)) {
echo "noactioncell";
}
else
{
echo "donecell";
}
?> text-center align-middle" >
<?php
if (!empty($log->control_number)) {
echo $log->control_number;
}
?>
</td>
<td class="<?php
if (empty($log->category)) {
echo "noactioncell";
}
else
{
echo "donecell";
}
?> text-center align-middle" >
<?php
if (!empty($log->category)) {
echo $log->category;
}
?>
</td>
<td class="<?php
if (empty($log->pr_date)) {
echo "noactioncell";
}
else
{
echo "donecell";
}
?> text-center align-middle" >
<?php
if (!empty($log->pr_date)) {
echo date("m/d/Y", strtotime($log->pr_date));
}
?>
</td>
<td class="<?php
if (empty($log->approve_budget )) {
echo "noactioncell";
}
else
{
echo "donecell";
}
?> text-center align-middle" >
<?php
if (!empty($log->approve_budget )) {
echo $log->approve_budget ;
}
?>
</td>
//Here is the column that i want to be a link to be downloaded
<td class="<?php
if (empty($log->file)) {
echo "noactioncell";
}
else
{
echo "donecell";
}
?> text-center align-middle" >
<?php
if (!empty($log->file )) {
echo $log->file ;
}
?>
</td>
////////////////////////////////////////////////////////////////////////
</tr>
<?php
}
}
?>
</tbody>
</table>
just create an anchor link
<?php
if (!empty($log->file )) {
echo '<a href="'.$log->file.'" target="_blank" >'.$log->file.'</a>';
}
Related
I have created a shortcode which renders this table on the frontend. At the moment the shortcode puts the content at the top of the page rather than respecting the location of where the shortcode is pasted in the editor.
How can i fix this?
<div id="cookie-container">
<div class="row justify-content-center mb-3">
<div class="col-12">
<h3>Essential Cookies</h3>
</div>
</div>
<table class="table table-bordered table-hover table-sm diva-cookie-table">
<thead class="diva-cookie-table__thead">
<tr>
<th style="width: 33%" class="diva-cookie-table__th">Name</th>
<th style="width: 33%" class="diva-cookie-table__th">Cookie</th>
<th style="width: 33%" class="diva-cookie-table__th">Purpose</th>
</tr>
</thead>
<tbody class="diva-cookie-table__tbody">
<tr>
<?php
$essential_cookies = carbon_get_theme_option( 'essential_cookies' );
foreach ( $essential_cookies as $cookie ) {
echo '<tr>';
if($cookie['name']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['name'];
echo '</td>';
}
if($cookie['cookies']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['cookies'];
echo '</td>';
}
if($cookie['usage']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['usage'];
echo '</td>';
}
}
echo '</tr>';
?>
</tr>
</tbody>
</table>
</div>
/**
* Construct Essential Cookies Shortcode
*/
function construct_essential_cookies_table()
{
ob_start();
include dirname( __FILE__ ) . '/partials/essential_cookie_table.php';
return ob_get_clean();
}
add_shortcode('diva_essential_cookies', 'construct_essential_cookies_table');
You need to include the full HTML code inside the php output buffer functions like that.
<?php ob_start(); ?>
<div id="cookie-container">
<div class="row justify-content-center mb-3">
<div class="col-12">
<h3>Essential Cookies</h3>
</div>
</div>
<table class="table table-bordered table-hover table-sm diva-cookie-table">
<thead class="diva-cookie-table__thead">
<tr>
<th style="width: 33%" class="diva-cookie-table__th">Name</th>
<th style="width: 33%" class="diva-cookie-table__th">Cookie</th>
<th style="width: 33%" class="diva-cookie-table__th">Purpose</th>
</tr>
</thead>
<tbody class="diva-cookie-table__tbody">
<tr>
<?php
$essential_cookies = carbon_get_theme_option( 'essential_cookies' );
foreach ( $essential_cookies as $cookie ) {
echo '<tr>';
if($cookie['name']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['name'];
echo '</td>';
}
if($cookie['cookies']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['cookies'];
echo '</td>';
}
if($cookie['usage']) {
echo '<td class="diva-cookie-table__title">';
echo $cookie['usage'];
echo '</td>';
}
}
echo '</tr>';
?>
</tr>
</tbody>
</table>
</div>
<?php return ob_get_clean();
Currently I have an overview of domains. I logged in with an account that has the contact ID of 197246. but it shows all of them. Here I want to filter my overview that the user which is logged in, sees his own domains.
So when ID 197246 logs in, show the domains that have contact id 197246. When ID 307890 logs in, show those domains.
This is my code so far. I guess here needs to be a filter.
<?php
unset($command);
$command = array(
"command" => "DomainsListActive"
);
$api = new Versio_api();
$versio = $api->api_send($command);
if($versio['success']==0) {
echo("Fout opgetreden. Fout code: ".$versio['command_response_code'].". Fout text: ".$versio['command_response_message']."");
}
else {
if($versio['total_count']>0)
{
require_once("includes/submenu.php");
?>
<div class="col-sm-9 col-md-9" style="width:80%;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Klantenpaneel</h3>
</div>
<div class="panel-body">
<form method="post" action="">
<table class="table table-striped">
<thead>
<tr>
<th>Domein</th>
<th>TLD</th>
<th>Verloop datum</th>
<th>Automatisch verlengen</th>
<th>contact ID</th>
</tr>
</thead>
<table class="table table-striped table-bordered">
<tbody>
<?php
$teller = 1;
while($versio['total_count']>=$teller) {
?>
<tr>
<td><a href="records.php?domain=<?php echo $versio['domain_'.$teller]; ?>&tld=<?php echo $versio['tld_'.$teller]; ?>">
<?php echo $versio['domain_'.$teller]; ?></a></td>
<td>.<?php echo $versio['tld_'.$teller]; ?></td>
<td><?php echo $versio['expiration_date_'.$teller]; ?></td>
<td><?php echo $versio['auto_renew_'.$teller]; ?></td>
<td><?php echo $versio['contactid_'.$teller]; ?></td>
</tr>
<?php $teller++;
}
?>
</tbody>
</table>
</form>
</div>
</div>
<?php
} else {
echo("Er zijn geen DNS records gevonden voor dit domein.");
}
}
?>
The documentation from Versio gives you an entire list of options in the call. One option you could do is check if the 'contactid_x' equals to the logged in user.
more information on their wiki right here
As an example, this would do the trick:
unset($command);
$command = array(
"command" => "DomainsListActive"
);
$api = new Versio_api();
$versio = $api->api_send($command);
if($versio['success']==0) {
echo("Fout opgetreden. Fout code: ".$versio['command_response_code'].". Fout text: ".$versio['command_response_message']."");
}
else {
if($versio['total_count']>0)
{
require_once("includes/submenu.php");
?>
<div class="col-sm-9 col-md-9" style="width:80%;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Klantenpaneel</h3>
</div>
<div class="panel-body">
<form method="post" action="">
<table class="table table-striped">
<thead>
<tr>
<th>Domein</th>
<th>TLD</th>
<th>Verloop datum</th>
<th>Automatisch verlengen</th>
<th>contact ID</th>
</tr>
</thead>
<table class="table table-striped table-bordered">
<tbody>
<?php
$teller = 1;
while($versio['total_count']>=$teller) {
if ($versio['contactid_'. $teller] != 197246 ) continue;
?>
<tr>
<td><a href="records.php?domain=<?php echo $versio['domain_'.$teller]; ?>&tld=<?php echo $versio['tld_'.$teller]; ?>">
<?php echo $versio['domain_'.$teller]; ?></a></td>
<td>.<?php echo $versio['tld_'.$teller]; ?></td>
<td><?php echo $versio['expiration_date_'.$teller]; ?></td>
<td><?php echo $versio['auto_renew_'.$teller]; ?></td>
<td><?php echo $versio['contactid_'.$teller]; ?></td>
</tr>
<?php $teller++;
}
?>
</tbody>
</table>
</form>
</div>
</div>
<?php
} else {
echo("Er zijn geen DNS records gevonden voor dit domein.");
}
}
?>
make sure to replace the ID with the ID from the user on line 41
I want to print binary tree (Below Image) in php from database value
And above is my database table structure
Here is what I tried, In this code I want to display binary tree of user id PX100
<?php
include 'db_connect.php';
$user_id = 'PX100';
$select_right_tree = $con->prepare("SELECT * FROM tbl_user_postion WHERE user_id=:user_id");
$select_right_tree->bindParam(":user_id", $user_id);
$select_right_tree->execute();
$fetch_right_tree = $select_right_tree->fetch(PDO::FETCH_ASSOC);
$ex_pos_right = $fetch_right_tree['pos_right'];
$ex_pos_left = $fetch_right_tree['pos_left'];
function right_part($pos_right) {
if(!empty($pos_right)) {
$select_left_tree = $con->prepare("SELECT pos_right, pos_left FROM tbl_user_postion WHERE user_id=:user_id");
$select_left_tree->bindParam(":user_id", $pos_right);
$select_left_tree->execute();
$fetch_left_tree = $select_left_tree->fetch(PDO::FETCH_ASSOC);
$user_right = $fetch_left_tree['pos_right'];
$user_left = $fetch_left_tree['pos_left'];
return array($user_right, $user_left);
if(!empty($user_right)) {
right_part($user_right);
}
if(!empty($user_left)) {
left_part($user_left);
}
}
}
function left_part($pos_left) {
if(!empty($pos_left)) {
$select_left_tree = $con->prepare("SELECT pos_right, pos_left FROM tbl_user_postion WHERE user_id=:user_id");
$select_left_tree->bindParam(":user_id", $pos_left);
$select_left_tree->execute();
$fetch_left_tree = $select_left_tree->fetch(PDO::FETCH_ASSOC);
$user_right = $fetch_left_tree['pos_right'];
$user_left = $fetch_left_tree['pos_left'];
return array($user_right, $user_left);
if(!empty($user_left)) {
left_part($user_left);
}
if(!empty($user_right)) {
right_part($user_right);
}
}
}
?>
<div class="tree">
<ul>
<li>
<img src="image/user.png" ><br/><?php echo $user_id; ?>
<ul>
<li>
<img src="image/user.png"><br/><?php echo $ex_pos_right; ?>
<?php
if(!empty($ex_pos_right))
{
list($pos_right1, $pos_left1) = right_part($ex_pos_right);
?>
<ul>
<li> <img src="image/user.png"><br/><?php echo $pos_right1; ?> </li>
<li> <img src="image/user.png"><br/><?php echo $pos_left1; ?> </li>
</ul>
<?php
}
?>
</li>
<li>
<img src="image/user.png"><br/><?php echo $ex_pos_left; ?>
<?php
if(!empty($ex_pos_left))
{
list($pos_right2, $pos_left2) = left_part($ex_pos_left);
?>
<ul>
<li> <img src="image/user.png"><br/><?php echo $pos_right2; ?> </li>
<li> <img src="image/user.png"><br/><?php echo $pos_left2; ?> </li>
</ul>
<?php
}
?>
</li>
</ul>
</li>
</ul>
</div>
Output of the above code is Here,
From database table, PX103 is a parent of PX108 and PX110, PX105 is parent of PX107 and PX111 , PX106 is parent of PX109. But PX108, PX110, PX107, PX111 and PX109 are not displaying in tree.
Please help me to sort out this problem.
Thankyou.
<table class="table table-bordered table-striped">
<tr>
<td width="950" >
<?php $m_id=NULL;$m_id=$_SESSION['id'];
$width=580;
for($lopp=0;$lopp<=3;$lopp++){
$tree=mysqli_query($sql,"select * from tree where distributer_id='".$m_id."'");
$m_id_fetch=mysqli_fetch_assoc($tree);
$left_m_id=$riggt_m_id="";
$tree_detaila=mysqli_query($sql,"select Name,yo_id from registration where yo_id='".$m_id."'");
if(!$tree_detaila) print mysqli_error($sql);
$detail=mysqli_fetch_assoc($tree_detaila);
if(!empty($m_id_fetch['pos_left'])) $left_m_id=$m_id_fetch['pos_left'];if(!empty($m_id_fetch['pos_right'])) $riggt_m_id=$m_id_fetch['pos_right'];
?> <table class="table-responsive" width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top" align="center"> <table class="table-responsive" width="<?php print $width; ?>" border="0" align="<?php if(!empty($m_id_fetch['pos_left']) && $lopp>0) print "left"; elseif(!empty($m_id_fetch['pos_right']) && $lopp>0) print "right" ?> " cellpadding="0" cellspacing="0">
<?php if($lopp==0) { ?> <tr>
<td width="<?php print $width; ?>" align="center"> <img src="dashboard/images/user.jpg" width="45" height="50" class="img-circle" />
</td>
</tr>
<tr>
<td align="center"><?php print strtoupper($detail['Name']); ?></td>
</tr>
<tr>
<td align="center"><?php print $detail['yo_id']; ?></td>
</tr><?php } else { print ' <tr>
<td colspan="2" align="left"></td>
</tr>'; } ?>
<tr>
<td align="center">
<tr>
<td colspan="2" align="<?php if(!empty($m_id_fetch['pos_left']) && $lopp>0) print "left"; elseif(!empty($m_id_fetch['pos_right']) && $lopp>0) print "right" ?>"><img src="img/p.png" width="<?php print $width=$width-90; ?> " height="5" /></td>
</tr>
<?php
if($left_m_id!="" )
{
$tree_detaila_l=mysqli_query($sql,"select Name,yo_id from registration where yo_id='".$m_id_fetch['pos_left']."'");
$detail_l=mysqli_fetch_assoc($tree_detaila_l);
}
if($riggt_m_id!="")
{
$tree_detaila_r=mysqli_query($sql,"select Name,yo_id from registration where yo_id='".$m_id_fetch['pos_right']."'");
$detail_r=mysqli_fetch_assoc($tree_detaila_r);
}
?>
<tr>
<?php if($left_m_id!="" ){ ?> <td align="left">
<a href='#' class='tt'> <img src="dashboard/images/user.jpg" width="45" height="50" class="img-circle" /> </a></td><?php } ?>
<?php if($riggt_m_id!="" ){ ?> <td align="right">
<a href='#' class='tt'> <img src="dashboard/images/user.jpg" width="45" height="50" class="img-circle" /> </a></td><?php } ?>
</tr>
<tr>
<?php if($left_m_id!="") { ?><td align=" left"><?php print $detail_l['Name']; ?></td><?php } ?> <?php if($riggt_m_id!="") { ?><td align=" right"><?php print $detail_r['Name']; ?></td><?php } ?>
</tr>
<tr>
<?php if($left_m_id!="") { ?><td align=" left">
<?php print $detail_l['yo_id']; ?>
</td><?php } ?> <?php if($riggt_m_id!="") { ?><td align=" right">
<?php print $detail_r['yo_id']; ?>
</td><?php } ?>
</tr>
</table></td>
</tr>
</table><?php $width=$width-100;$m_id=$m_id_fetch['pos_right']; } ?>
</td>
</tr>
</table>`enter code here`
I have to print something like No emails found in my view.
My Controller looks:
public function viewEmailMessage()
{
if(($this->session->userdata('username')!=""))
{
$data =array();
$data['email']=$this->adminModel->viewEmailMessageModel();
$this->load->view('admin/viewEmailMessages',$data);
}
else
{
$this->load->view('admin/login');
}
}
My Model looks:
public function viewEmailMessageModel()
{
$this->db->select("*");
$this->db->from('message');
$this->db->order_by("id", "desc");
$query = $this->db->get();
return $result=$query->result();
}
My View looks:
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
?>
</tbody>
</table>
How to modify my Controller, model & view. For I have to print something like "No Emails Found" in the same view when the message table is empty.
In view try this
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
if(count($email) > 0 ){
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
} else {
echo "msg here";
}
?>
</tbody>
</table>
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
if($email and other condition){
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
}
else{
echo your message;
}
?>
</tbody>
</table>
use count() function
and not able to use if(!empty($email)) for array variable use count()
if(count($email)==0)
{
echo "NO email found";
}
else
{
foreach($email as $row)
{
.........
}
}
I'm pretty much done with my shopping cart. I'm able to update the cart,but when I click on the delete button next to the item, it gets redirected to a blank page.
This is the top of my cart.php:
<?php
session_start();
include ("db_connection.php");//include database connection
if (isset($_SESSION['cart'])) {
if(isset($_GET['ebook_id']) && !isset($_POST['update'])){
$statement=$_SESSION['cart'];
$find=false;
$number=0;
for($i=0;$i<count($statement);$i++){
if($statement[$i]['ebook_id']==$_GET['ebook_id']){
$find=true;
$number=$i;
}
}
if($find==true){
$statement[$number]['quantity']=$statement[$number]['quantity']+1;
$_SESSION['cart']=$statement;
}else{
$ebook_title="";
$price=0;
$ebook_image="";
$query=mysqli_query($con,"SELECT * FROM ebooks WHERE ebook_id=".$_GET['ebook_id']);
while ($row=mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$ebook_title=$row['ebook_title'];
$price=$row['price'];
$ebook_image=$row['ebook_image'];
}
$newData=array('ebook_id'=>$_GET['ebook_id'],
'ebook_title'=>$ebook_title,
'price'=>$price,
'ebook_image'=>$ebook_image,
'quantity'=>1);
array_push($statement, $newData);
$_SESSION['cart']=$statement;
}
}
}else{
if(isset($_GET['ebook_id'])){
$ebook_title="";
$ebook_image="";
$price=0;
$query=mysqli_query($con,"SELECT * FROM ebooks WHERE ebook_id=".$_GET['ebook_id']);
while ($row=mysqli_fetch_array($query,MYSQLI_ASSOC)) {
extract ($row);
$ebook_title=$row['ebook_title'];
$ebook_image=$row['ebook_image'];
$price=$row['price'];
}
$statement[]= array('ebook_id' => $_GET['ebook_id'],'ebook_title' => $ebook_title,'ebook_image' => $ebook_image,'price' => $price,'quantity' => 1);
$_SESSION['cart']=$statement;
}
}
?>
This is my cart form:
<form method="POST">
<table class="table">
<thead>
<tr>
<th colspan="2">E-book</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if (isset($_POST['update'])){
$arrquantity=$_POST['quantity'];
//check validate quantity
$valid = 1;
for ($i=0; $i < count($arrquantity); $i++) {
if (!is_numeric($arrquantity[$i]) || $arrquantity[$i] < 1) {
$valid=0;
break;
}
}
if ($valid == 1){
$cart = unserialize (serialize($_SESSION['cart']));
for ($i=0;$i<count($cart);$i++) {
$cart[$i]['quantity']=$arrquantity[$i];
}
}else{
$error= "Quantity is invalid";
}
$_SESSION['cart']=$cart;
}
//delete ebook in cart
$total=0;
if (isset($_SESSION['cart'])) {
$data=$_SESSION['cart'];
$total=0;
for ($i=0;$i<count($data);$i++) {
?>
<?php echo isset($error) ? $error :'';?>
<div class="ebook">
<td><img src="<?php echo $data[$i]['ebook_image'];?>"></td>
<td><?php echo $data[$i]['ebook_title'];?></td>
<td>£<?php echo $data[$i]['price'];?></td>
<td><input type="text" value="<?php echo $data[$i]['quantity'];?>" data-price="<?php echo $data[$i]['price'];?>" data-id="<?php echo $data[$i]['ebook_id'];?>" class="quantity" name="quantity"></td>
<td class="subtotal">£<?php echo $data[$i]['price']*$data[$i]['quantity'];?></td>
<td><i class="fa fa-trash-o"></i>
</div>
</tr>
<?php
$total=($data[$i]['price']*$data[$i]['quantity'])+$total;
}
}else{
echo "<p class='text-muted'>Your shopping cart is empty</p>";
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="5">Total Price</th>
<th colspan="2" id="total">£<?php echo $total; ?></th>
</tr>
</tfoot>
</table>
</div>
<!-- /.table-responsive -->
<div class="box-footer">
<div class="pull-left">
<i class="fa fa-chevron-left"></i>Continue shopping
</div>
<div class="pull-right">
<button type="submit" class="btn btn-default" name="update"><i class="fa fa-refresh"></i>Update</button>
<button type="submit" class="btn btn-primary">Checkout<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
</form>
Finally, this is the jquery to delete an item:
$(".delete").click(function(e){
e.preventDefault();
var id=$(this).attr('data-id');
$(this).parentsUntil('.ebook').remove();
$.post('./js/delete.php',{
Id:ebook_id
},function(a){
location.href="cart.php?";
});
And the delete.php page to remove the item from the cart session:
<?php
session_start();
$statement=$_SESSION['cart'];
for($i=0;$i<count($statement);$i++){
if($statement[$i]['ebook_id']!=$_POST['ebook_id']){
$newData[]=array(
'ebook_id'=>$statement[$i]['ebook_id'],
'ebook_title'=>$statement[$i]['ebook_title'],
'price'=>$statement[$i]['price'],
'ebook_image'=>$statement[$i]['ebook_image'],
'quantity'=>$statement[$i]['quantity']
);
}
}
if(isset($newData)){
$_SESSION['cart']=$newData;
}else{
unset($_SESSION['cart']);
echo '0';
}
?>
I'm new to ecommerce websites. I would really appreciate any help.
Thanks
On your delete page
<?php
if(isset($_POST['ebook_id'])){
$query=mysqli_query($con,"DELETE FROM ebooks WHERE ebook_id=".$_POST['ebook_id']);
if($query==true) {
return true;
}else {
return false;
}
}
Your JS code should be
$(".delete").click(function(e){
e.preventDefault();
var id=$(this).attr('data-id');
$.ajax({
type:"POST",
url: "delete.php",
data: {ebook_id: id},
}).done(function(data) {
$("#row_"+id+"").hide();
});
});
Your form
<form method="POST">
<table class="table">
<thead>
<tr>
<th colspan="2">E-book</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['update'])){
$arrquantity=$_POST['quantity'];
//check validate quantity
$valid = 1;
for ($i=0; $i < count($arrquantity); $i++) {
if (!is_numeric($arrquantity[$i]) || $arrquantity[$i] < 1) {
$valid=0;
break;
}
}
if ($valid == 1){
$cart = unserialize (serialize($_SESSION['cart']));
for ($i=0;$i<count($cart);$i++) {
$cart[$i]['quantity']=$arrquantity[$i];
}
}else{
$error= "Quantity is invalid";
}
$_SESSION['cart']=$cart;
}
//delete ebook in cart
$total=0;
if (isset($_SESSION['cart'])) {
$data=$_SESSION['cart'];
$total=0;
for ($i=0;$i<count($data);$i++) {
?>
<?php echo isset($error) ? $error :'';?>
//i don't know why you had open div here, so i replaced the div with tr and tr should have been inside the loop
<tr class="ebook" id="row_<?php echo $data[$i]['ebook_id'];?>">
<td><img src="<?php echo $data[$i]['ebook_image'];?>"></td>
<td><?php echo $data[$i]['ebook_title'];?></td>
<td>£<?php echo $data[$i]['price'];?></td>
<td><input type="text" value="<?php echo $data[$i]['quantity'];?>" data-price="<?php echo $data[$i]['price'];?>" data-id="<?php echo $data[$i]['ebook_id'];?>" class="quantity" name="quantity"></td>
<td class="subtotal">£<?php echo $data[$i]['price']*$data[$i]['quantity'];?></td>
<td><i class="fa fa-trash-o"></i>
</tr>
</tr>
<?php
$total=($data[$i]['price']*$data[$i]['quantity'])+$total;
}
}else{
echo "<p class='text-muted'>Your shopping cart is empty</p>";
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="5">Total Price</th>
<th colspan="2" id="total">£<?php echo $total; ?></th>
</tr>
</tfoot>
</table>
</div>
<!-- /.table-responsive -->
<div class="box-footer">
<div class="pull-left">
<i class="fa fa-chevron-left"></i>Continue shopping
</div>
<div class="pull-right">
<button type="submit" class="btn btn-default" name="update"><i class="fa fa-refresh"></i>Update</button>
<button type="submit" class="btn btn-primary">Checkout<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>