i have this code in index.php :
<?php require 'class.php';require_once './session.php';$conn = new db_class();$read = $conn->read();$data = [];while($fetch = $read->fetch_array()){
$data[] = $fetch;}?>
<table class = "table table-bordered table-responsive ">
<thead>
<tr>
<th>Segment</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $fetch): ?>
<tr>
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']?>">
<td class="segment" contenteditable="true"><?= $fetch['segment'] ?></td>
<td class="text-center">
<button class = "btn btn-default action-btn" data-id="<?= $fetch['id'] ?>" data-action="update">
<span class = "glyphicon glyphicon-edit"></span> Update
</button>
|
<button class = "btn btn-success action-btn" data-id="<?= $fetch['id'] ?>" type="submit" data-action="activate">
<span class = "glyphicon glyphicon-check"></span> Activate
</button>
|
<button class = "btn btn-danger action-btn" data-id="<?= $fetch['id'] ?>" data-action="deactivate">
<span class = "glyphicon glyphicon-folder-close"></span> deactivate
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
and this the function in class.php
public function read()
{
$stmt = $this->conn->prepare("SELECT id,segment FROM `segments`") or die($this->conn->error);
if ($stmt->execute()) {
$result = $stmt->get_result();
return $result;
}
}
all i want is to show if activation is disabled to show only activate button and if activation is on to show only the deactivate button,
i use 0 for deactivation and 1 for activation
First you need to hide the deactivate button use style display to hide
button. Write click event on activate button then use jquery hide/show to hide activate button & show deactivate button.
$(".activate-btn").click(function() {
$(this).hide();
$(".deactivate-btn").show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class = "table table-bordered table-responsive ">
<thead>
<tr>
<th>Segment</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $fetch): ?>
<tr>
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']?>">
<td class="segment" contenteditable="true"><?= $fetch['segment'] ?></td>
<td class="text-center">
<button class = "btn btn-default action-btn" data-id="<?= $fetch['id'] ?>" data-action="update">
<span class = "glyphicon glyphicon-edit"></span> Update
</button>
|
<button class = "btn btn-success activate-btn action-btn" data-id="<?= $fetch['id'] ?>" type="submit" data-action="activate">
<span class = "glyphicon glyphicon-check"></span> Activate
</button>
<button style="display:none" class = "btn btn-danger deactivate-btn action-btn " data-id="<?= $fetch['id'] ?>" data-action="deactivate">
<span class = "glyphicon glyphicon-folder-close"></span> deactivate
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Related
I already create a delete button, but when I click it no showing any error message and the cart item and the item in database no get deleted.
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
This is the delete button function
if(isset($_POST['delete_cart_btn']))
{
$prod_id = mysqli_real_escape_string($con, $_POST['prod_id']);
$prod_query = "SELECT * FROM carts WHERE id='$prod_id' ";
$prod_query_run = mysqli_query($con, $prod_query);
$prod_data = mysqli_fetch_array($prod_query_run);
$image = $prod_data['image'];
$delete_query = "DELETE FROM carts WHERE id='$prod_id' ";
$delete_query_run = mysqli_query($con, $delete_query);
if($delete_query_run)
{
if(file_exists("../assets/images/products/".$image))
{
unlink("../assets/images/products/".$image);
}
echo 200;
}
else
{
echo 404;
}
}
Here my database
enter image description here
Here the button cart script and the button function
enter image description here
enter image description here
Here the full code the cart
<div id="fullCart" class="row">
<div class="col-sm-12 col-md-12 col-md-offset-1">
<table class="table table-hover">
<thead colspan="4">
<tr>
<p class="text-center"><strong><span style="font-size: 25px;"><i class="fa fa-shopping-cart" style="font-size:25px;color:black"></i> My Cart</span></strong></p>
</tr>
</thead>
<hr>
<thead>
<tr>
<th class="text-center">Product</th>
<th class="text-center">Quantity</th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$subTotal = 0;
$quantity = 0;
$tax = 10;
$items = getCartItems();
foreach ($items as $citem) {
$subTotal += $citem['prod_qty'] * $citem['selling_price'];
$quantity += $citem['prod_qty'];
?>
<tr id="item_<?= $citem['prod_id']; ?>">
<td class="col-sm-8 col-md-6">
<div class="media">
<img class="media-object" src="assets/images/products/<?= $citem['image']; ?>" style="width: 100px; height: 100px;">
<h4 class="media-heading" style="position:relative; left:110px; top:-100px;"><?= $citem['name']; ?></h4>
</div>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><?= $citem['prod_qty']; ?></strong>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><span style="font-size: 18px;">$</span><span id="price"><?= number_format( $citem['selling_price'], 2 ); ?></span>
</strong>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><span style="font-size: 18px;">$</span><span id="totalPrice_<?= $citem['prod_id']; ?>"><?= number_format( $citem['prod_qty'] * $citem['selling_price'], 2 ); ?></span>
</strong>
</td>
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="4" align="right">Subtotal</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="subTotal"><?= number_format( $subTotal, 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">Taxes</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="taxes"><?= number_format( $tax * $quantity, 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">Total</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="finalPrice"><?= number_format( $subTotal+($tax * $quantity), 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">
<a href="index.php" class="btn btn-default">
<span class="glyphicon glyphicon-shopping-cart"></span> Place Order
</a>
</td>
<td >
<a href="checkout.php" class="btn btn-success">
Order <span class="glyphicon glyphicon-play"></span>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
It seems you don't have a form to submit
There is no action when there is no form
Add a form tag and change your button type to submit
you need to data pass by POST so i 've added a method="POST" attribute to my form
<form>
<td class="col-sm-1 col-md-1" action="file_name.php" method="POST">
<button type="submit" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
</form>
instead of file_name.php put your php script file name
You did not name the button, so it doesn't send the data in the form.
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
if(isset($_POST['delete_cart_btn']))
{
$prod_id = mysqli_real_escape_string($con, $_POST['delete_cart_btn']);
$prod_query = "SELECT * FROM carts WHERE id='$prod_id' ";
$prod_query_run = mysqli_query($con, $prod_query);
$prod_data = mysqli_fetch_array($prod_query_run);
$image = $prod_data['image'];
$delete_query = "DELETE FROM carts WHERE id='$prod_id' ";
$delete_query_run = mysqli_query($con, $delete_query);
if($delete_query_run)
{
if(file_exists("../assets/images/products/".$image))
{
unlink("../assets/images/products/".$image);
}
echo 200;
}
else
{
echo 404;
}
}
<div class="container">
<h3 class="text-center">Hotel/Admin Joint Panel</h3>
<table class="table table-bordered">
<tr>
<th>Food_ID</th>
<th>Cuisines</th>
<th >Description</th>
<th >Price</th>
<th >Image</th>
<th >Date</th>
<th width="50px">Action</th>
</tr>
<?php
include_once 'mainclass.php';
$confirmThread = new menuDatabase();
$sql = "SELECT * FROM gallery";
$users = mysqli_query($confirmThread->getCon(),$sql);
while($user = $users->fetch_assoc()){
?>
<tr id="<?php echo $user['idGallery'] ?>" >
<td ><?php echo $user['idGallery'] ?></td>
<td><?php echo $user['titleGallery'] ?></td>
<td><?php echo $user['descGallery'] ?></td>
<td><?php echo $user['price'] ?></td>
<!-- <td><?php echo ("data:image/jpeg;base64,".base64_encode($user['image'] )) ?></td> -->
<td><?php echo '<img src="data:image/jpeg;base64,'.base64_encode($user['image'] ).'">'
?></td>
<td width="100px"><?php echo $user['samaye'] ?></td>
<td>
<button class="btn btn-danger btn-sm remove">Delete</button>
<button style="margin-top: 2px" id="createOnly" class="btn btn-danger"> Create Menu</button>
<button style="margin-top: 2px" id="updateOnly" id="hi" class="btn btn-danger btn-sm "> <a class="update" href="upload.php">Update</a></button>
</td>
</tr>
<?php } ?>
</table>
</div> <!-- container / end -->
I wanted to update the database using an update button which is in Menu.php. What I wanted is, when I clicked on the update button(in menu.php) it should grab the food_id(primary key) and remember this for Upload.php, from where I am doing real updating by getting all new values.
You can change the following statement to
<td>
<button class = "btn btn-danger btn-sm remove">Delete</button>
<button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger"> Create Menu</button>
<button style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm"> <a class = "update" href = "upload.php">Update</a></button>
</td>
this. This will act as a form (Only for the update button) and you can get these values to your update.php. The id that you need is hidden. From update.php you can do what you need to.
<td>
<button class = "btn btn-danger btn-sm remove">Delete</button>
<button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger"> Create Menu</button>
<form method = "post" action = "upload.php">
<input type = "hidden" name="food_id" value="<?php echo $user['idGallery']; ?>"/>
<button type = "submit" style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm">Update</button>
</form>
</td>
Or else you can do this by using Query Parameter like this,
<td>
<button class = "btn btn-danger btn-sm remove">Delete</button>
<button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger"> Create Menu</button>
<button style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm"> <a class = "update" href = "upload.php?foodID=<?php echo $user['idGallery']; ?>">Update</a></button>
</td>
and from your update.php you can get the result like this,
$foodID = $_GET["foodID"];
Hope this helps you!
I have one table and in this table, I have two button Update and Disable I want to hide those buttons
I trying like this
<table id="example1" class="table table-bordered table-striped table-sm" style=" overflow: auto; ">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php
$hide = 'OFF';
if($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis){?>
<tr>
<td><?php echo $dis->disp_ch_no;?></td>
<td><?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?></td>
<td><?php echo $dis->from_branch_name;?></td>
<td><a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a></td>
<td><a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
</tr>
<?php }?>
</table>
this is my table
How can I hide these buttons
Try this,
<?php
$thswitch = 'OFF';
if($thswitch == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
whenever you want to show just $thswitch = 'ON'; it
You have to check the if () for each row as we did in th. Like:
<table id="example1" class="table table-bordered table-striped table-sm" style="overflow: auto;">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php $hide = 'OFF';
if ($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis) { ?>
<tr>
<td> <?php echo $dis->disp_ch_no;?> </td>
<td> <?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?> </td>
<td> <?php echo $dis->from_branch_name;?> </td>
<?php if ($hide == 'ON') { ?>
<td>
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
<td>
<a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
Or by using CSS you can hide this columns as:
Create a CSS class like:
.hidethisColumn { display: none !important; }
Use it in you table as:
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Update</th>
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Delete</th>
Similarly in rows inside foreach():
<td class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
I have a table of each request filed by the user with corresponding actions to it. When I click on the update button, it doesnt load the view after submitting it.
This is my html code:
<table id="dataTableRequestDrafts" class="table table-striped table-bordered data-table-drafts" style="width:100%">
<thead>
<tr>
<th style="display: none;">Request ID</th>
<th>Request Type</th>
<th>Date Requested</th>
<th>Date Last Updated</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($param_drafts as $drafts){?>
<tr>
<td class="id" style="display: none;"><?php echo $drafts['idx']?></td>
<td class="type"><?php echo $drafts['request_type']?></td>
<td><?php echo $drafts['date_requested']?></td>
<td><?php echo $drafts['date_updated']?></td>
<td class="text-warning"><?php echo $drafts['status']?></td>
<td align="center">
<form action="<?php echo base_url('dashboard/staff/request/update_request_view'); ?>" method="post">
<input type="text" name="request_id" value="<?php echo $drafts['idx']?>" style="display: none;">
<button type="button" class="btn waves-effect waves-light btn-primary view-button"><i class="fa fa-eye"></i> View</button> <button type="submit" class="btn waves-effect waves-light btn-info update-button"><i class="fa fa-edit"></i> Update</button> <button type="button" class="btn waves-effect waves-light btn-danger delete-button" data-url="<?php echo base_url('dashboard/staff/request/delete');?>"><i class="fa fa-trash-o"></i> Delete</button>
</form>
</td>
</td>
</tr>
<?php } ?>
</tbody>
</table>
This is my function in the controller:
public function update_request_view()
{
$data = new stdClass;
$data->param_menu = 'request';
$idx = $this->input->post('request_id');
$type = $this->staffrequisition_model->getRequestType($idx);
$typeLower = strtolower($string = str_replace(' ', '', $type));
$commonContents = $this->staffrequisition_model->selectItem(array('idx'=> $idx));
$uncommonContents = json_decode($commonContents->contents);
$data->param_request = array_merge((array) $commonContents, (array) $uncommonContents);
$this->load->view('dashboard/staff/update_'.$typeLower.'_view', $data);
}
The view is seen in the response but it doesnt load the view. I was gonna use ajax but it would be tedious to load the data of the request in each input in the view and I want to return the whole html page not just a div.
Can you show the response here.
sometimes the response can't handle by browser. so it can't appear
I want to know how should we use div tags inside a table in PHP code. This is my code. Please tell me how to use it properly.
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td>echo '<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>';
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>
I have tried using inverted comma's and braces but still, it shows error. What needs to be done here?
You can write the div inside table. Don't put all table inside php tag. remove html outside the <?php ?> php code. after that whenever you want to echo any value just used the php.
Customize your code like below,
<table>
<tbody>
<?php
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img width='90px' height='90px' src='imageView.php?id=<?php echo $row["id"]; ?>' /> </td>
<td><?php echo $row['item_name']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td>
<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>
<td> <button>submit</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
Within a double quote you can use a single quote
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td><div class='col-md-1 col-sm-3 col-xs-6 c-cart-qty'>
<div class='c-input-group c-spinner'>
<input type='text' class='form-control c-item-1' value='1'>
<div class='c-input-group-btn-vertical'>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-up'></i>
</button>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-down'></i>
</button>
</div>
</div>
</div>
</td>;
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>