I have this code right here:
#foreach($products as $p)
<tr>
<td class="col-md-6">
<div class="media">
<a class="thumbnail pull-left" href="#"> <img class="media-object" src="{{URL::to($p['image'])}}" style="width: 72px; height: 72px;"> </a>
<div class="media-body">
<span style="padding-left: 20px">Pavadinimas: </span><span class="text-warning"><strong>{{$p['title']}}</strong></span>
</div>
</div>
</td>
<td class="col-md-1" style="text-align: center">
<input type="number" class="form-control" id="quantity" value="{{$p['quantity']}}">
</td>
<td class="col-md-1 text-center">
<strong>{{$p['price']}} EUR</strong>
</td>
<td class="col-md-1 text-center">
<strong>{{$p['price']*$p['quantity']}} EUR</strong>
</td>
<td class="col-md-1">
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-remove"></span> Pašalinti
</button>
</td>
</tr>
#endforeach
the $products is in foreach loop and I don't know how to get the all price if there're two, three or more products because I don't know how to set variable outside foreach loop. Because if I add this code in foreach loop wich is not right now added in foreach loop:
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Subtotal</h5></td>
<td class="text-right"><h5><strong> EUR</strong></h5></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Another taxes</h5></td>
<td class="text-right"><h5><strong>1.44 EUR</strong></h5></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h3>Total</h3></td>
<td class="text-right"><h3><strong> EUR</strong></h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-shopping-cart"></span> Žiūrėti kitas prekes
</button>
</td>
<td>
<button type="button" class="btn btn-success">Užsakyti
<span class="glyphicon glyphicon-play"></span>
</button>
</td>
</tr>
This code will just duplicate. So any suggestion how to get total price of all products in cart without adding this piece of code in foreach loop ?
If you are just trying the get the total of the $products collection, then try {{ $products->sum('amount'); }}
Alternatively, you could use JavaScript to dynamically update the total. If that value is then needed to be passed into a controller on form::submit, then you could store the value in a hidden input.
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;
}
}
I'm new to Laravel. I'm getting this issue from a long while. I've added a route to a page in web.php but it is showing a blank page instead of going to that page.
Here are the routes in web.php:
Route::group(['middleware' => ['auth','admin']], function() {
//For Admin Dashboard
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
//For listing users
Route::get('/users-list', function () {
return view('admin.users');
});
});
The users-list route is not working. The users.blade.php file is placed in admin folder.
I'm trying to add the path directory to url but still not working. Here is another thing I'm trying.
Navbar
<li>
<!-- <a href="{{ url('/admin/users') }}"> -->
<a href="{{ url('/users-list') }}">
<i class="now-ui-icons users_single-02"></i>
<p>Users Profiles</p>
</a>
</li>
Here is my views directory
I'm trying to access it from here but still no results, same blank page. There's something wrong which I'm not able to find out. Any suggestion will be highly appreciated.
I'll be happy to provide any sorts of other details if required.
Replace your route with below route code:
Route::get('users-list', function () {
return view('admin/users');
});
Blade file code:
<li>
<!-- <a href="{{ url('/admin/users') }}"> -->
<a href="{{ url('users-list') }}">
<i class="now-ui-icons users_single-02"></i>
<p>Users Profiles</p>
</a>
</li>
just change your url in this way
Navbar
<li>
<a href="{{ url('/admin/users-list') }}">
<i class="now-ui-icons users_single-02"></i>
<p>Users Profiles</p>
</a>
Alright everyone, thanks alot for your answers and suggestions. I think I have found my issue.
I was using a layout file for dashboard.blade.php and users-list.blade.php named master.blade.php. And issue was in that file as it was not displaying output. I've corrected it and it worked.
Here is my users.blade.php
#extends('layouts.master')
#section('title')
Users Profiles | TestWeb
#endsection
#section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title"> Simple Table</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>
Name
</th>
<th>
Country
</th>
<th>
City
</th>
<th class="text-right">
Salary
</th>
</thead>
<tbody>
<tr>
<td>
Dakota Rice
</td>
<td>
Niger
</td>
<td>
Oud-Turnhout
</td>
<td class="text-right">
$36,738
</td>
</tr>
<tr>
<td>
Minerva Hooper
</td>
<td>
Curaçao
</td>
<td>
Sinaai-Waas
</td>
<td class="text-right">
$23,789
</td>
</tr>
<tr>
<td>
Sage Rodriguez
</td>
<td>
Netherlands
</td>
<td>
Baileux
</td>
<td class="text-right">
$56,142
</td>
</tr>
<tr>
<td>
Philip Chaney
</td>
<td>
Korea, South
</td>
<td>
Overland Park
</td>
<td class="text-right">
$38,735
</td>
</tr>
<tr>
<td>
Doris Greene
</td>
<td>
Malawi
</td>
<td>
Feldkirchen in Kärnten
</td>
<td class="text-right">
$63,542
</td>
</tr>
<tr>
<td>
Mason Porter
</td>
<td>
Chile
</td>
<td>
Gloucester
</td>
<td class="text-right">
$78,615
</td>
</tr>
<tr>
<td>
Jon Porter
</td>
<td>
Portugal
</td>
<td>
Gloucester
</td>
<td class="text-right">
$98,615
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="card card-plain">
<div class="card-header">
<h4 class="card-title"> Table on Plain Background</h4>
<p class="category"> Here is a subtitle for this table</p>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>
Name
</th>
<th>
Country
</th>
<th>
City
</th>
<th class="text-right">
Salary
</th>
</thead>
<tbody>
<tr>
<td>
Dakota Rice
</td>
<td>
Niger
</td>
<td>
Oud-Turnhout
</td>
<td class="text-right">
$36,738
</td>
</tr>
<tr>
<td>
Minerva Hooper
</td>
<td>
Curaçao
</td>
<td>
Sinaai-Waas
</td>
<td class="text-right">
$23,789
</td>
</tr>
<tr>
<td>
Sage Rodriguez
</td>
<td>
Netherlands
</td>
<td>
Baileux
</td>
<td class="text-right">
$56,142
</td>
</tr>
<tr>
<td>
Philip Chaney
</td>
<td>
Korea, South
</td>
<td>
Overland Park
</td>
<td class="text-right">
$38,735
</td>
</tr>
<tr>
<td>
Doris Greene
</td>
<td>
Malawi
</td>
<td>
Feldkirchen in Kärnten
</td>
<td class="text-right">
$63,542
</td>
</tr>
<tr>
<td>
Mason Porter
</td>
<td>
Chile
</td>
<td>
Gloucester
</td>
<td class="text-right">
$78,615
</td>
</tr>
<tr>
<td>
Jon Porter
</td>
<td>
Portugal
</td>
<td>
Gloucester
</td>
<td class="text-right">
$98,615
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
And #extends('layouts.master')
#section('title')
Users Profiles | TestWeb
#endsection
#section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title"> Simple Table</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>
Name
</th>
<th>
Country
</th>
<th>
City
</th>
<th class="text-right">
Salary
</th>
</thead>
<tbody>
<tr>
<td>
Dakota Rice
</td>
<td>
Niger
</td>
<td>
Oud-Turnhout
</td>
<td class="text-right">
$36,738
</td>
</tr>
<tr>
<td>
Minerva Hooper
</td>
<td>
Curaçao
</td>
<td>
Sinaai-Waas
</td>
<td class="text-right">
$23,789
</td>
</tr>
<tr>
<td>
Sage Rodriguez
</td>
<td>
Netherlands
</td>
<td>
Baileux
</td>
<td class="text-right">
$56,142
</td>
</tr>
<tr>
<td>
Philip Chaney
</td>
<td>
Korea, South
</td>
<td>
Overland Park
</td>
<td class="text-right">
$38,735
</td>
</tr>
<tr>
<td>
Doris Greene
</td>
<td>
Malawi
</td>
<td>
Feldkirchen in Kärnten
</td>
<td class="text-right">
$63,542
</td>
</tr>
<tr>
<td>
Mason Porter
</td>
<td>
Chile
</td>
<td>
Gloucester
</td>
<td class="text-right">
$78,615
</td>
</tr>
<tr>
<td>
Jon Porter
</td>
<td>
Portugal
</td>
<td>
Gloucester
</td>
<td class="text-right">
$98,615
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="card card-plain">
<div class="card-header">
<h4 class="card-title"> Table on Plain Background</h4>
<p class="category"> Here is a subtitle for this table</p>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>
Name
</th>
<th>
Country
</th>
<th>
City
</th>
<th class="text-right">
Salary
</th>
</thead>
<tbody>
<tr>
<td>
Dakota Rice
</td>
<td>
Niger
</td>
<td>
Oud-Turnhout
</td>
<td class="text-right">
$36,738
</td>
</tr>
<tr>
<td>
Minerva Hooper
</td>
<td>
Curaçao
</td>
<td>
Sinaai-Waas
</td>
<td class="text-right">
$23,789
</td>
</tr>
<tr>
<td>
Sage Rodriguez
</td>
<td>
Netherlands
</td>
<td>
Baileux
</td>
<td class="text-right">
$56,142
</td>
</tr>
<tr>
<td>
Philip Chaney
</td>
<td>
Korea, South
</td>
<td>
Overland Park
</td>
<td class="text-right">
$38,735
</td>
</tr>
<tr>
<td>
Doris Greene
</td>
<td>
Malawi
</td>
<td>
Feldkirchen in Kärnten
</td>
<td class="text-right">
$63,542
</td>
</tr>
<tr>
<td>
Mason Porter
</td>
<td>
Chile
</td>
<td>
Gloucester
</td>
<td class="text-right">
$78,615
</td>
</tr>
<tr>
<td>
Jon Porter
</td>
<td>
Portugal
</td>
<td>
Gloucester
</td>
<td class="text-right">
$98,615
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
And master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="apple-touch-icon" sizes="76x76" href="/assets/img/apple-icon.png">
<link rel="icon" type="image/png" href="/assets/img/favicon.png">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>
#yield('title')
</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
<!-- Fonts and icons -->
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700,200" rel="stylesheet" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<!-- CSS Files -->
<link href="{{ asset('assets/css/bootstrap.min.css') }}" rel="stylesheet" />
<link href="{{ asset('assets/css/now-ui-dashboard.css?v=1.3.0') }}" rel="stylesheet" />
<!-- CSS Just for demo purpose, don't include it in your project -->
<link href="{{ asset('assets/demo/demo.css') }}" rel="stylesheet" />
</head>
<body class="">
<div class="wrapper ">
<div class="sidebar" data-color="orange">
<!--
Tip 1: You can change the color of the sidebar using: data-color="blue | green | orange | red | yellow"
-->
<div class="logo">
<a href="http://www.creative-tim.com" class="simple-text logo-normal">
| TestWeb |
</a>
</div>
<div class="sidebar-wrapper" id="sidebar-wrapper">
#include('inc.admin_navbar')
</div>
</div>
<div class="main-panel" id="main-panel">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-transparent bg-primary navbar-absolute">
<div class="container-fluid">
<div class="navbar-wrapper">
<div class="navbar-toggle">
<button type="button" class="navbar-toggler">
<span class="navbar-toggler-bar bar1"></span>
<span class="navbar-toggler-bar bar2"></span>
<span class="navbar-toggler-bar bar3"></span>
</button>
</div>
<a class="navbar-brand" href="#pablo">Table List</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-bar navbar-kebab"></span>
<span class="navbar-toggler-bar navbar-kebab"></span>
<span class="navbar-toggler-bar navbar-kebab"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navigation">
<form>
<div class="input-group no-border">
<input type="text" value="" class="form-control" placeholder="Search...">
<div class="input-group-append">
<div class="input-group-text">
<i class="now-ui-icons ui-1_zoom-bold"></i>
</div>
</div>
</div>
</form>
<ul class="navbar-nav">
<!-- Logout Button Starts -->
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
<!-- Logout Button Ends -->
</ul>
</div>
</div>
</nav>
<!-- End Navbar -->
<div class="panel-header panel-header-sm">
</div>
<div class="content">
#yield('content')
</div>
<footer class="footer">
<div class="container-fluid">
<nav>
<ul>
<li>
<a href="#">
TestWeb
</a>
</li>
<li>
<a href="#">
About Us
</a>
</li>
<li>
<a href="#">
Blog
</a>
</li>
</ul>
</nav>
<div class="copyright" id="copyright">
<script>
document.getElementById('copyright').appendChild(document.createTextNode(new Date().getFullYear()))
</script>
</div>
</div>
</footer>
</div>
</div>
<!-- Core JS Files -->
<script src="{{ asset('assets/js/core/jquery.min.js') }}"></script>
<script src="{{ asset('assets/js/core/popper.min.js') }}"></script>
<script src="{{ asset('assets/js/core/bootstrap.min.js') }}"></script>
<script src="{{ asset('assets/js/plugins/perfect-scrollbar.jquery.min.js') }}"></script>
<!-- Google Maps Plugin -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE"></script>
<!-- Chart JS -->
<script src="{{ asset('assets/js/plugins/chartjs.min.js') }}"></script>
<!-- Notifications Plugin -->
<script src="{{ asset('assets/js/plugins/bootstrap-notify.js') }}"></script>
<!-- Control Center for Now Ui Dashboard: parallax effects, scripts for the example pages etc -->
<script src="{{ asset('assets/js/now-ui-dashboard.min.js?v=1.3.0') }}" type="text/javascript"></script>
<!-- Now Ui Dashboard DEMO methods, don't include it in your project! -->
<script src="{{ asset('assets/demo/demo.js') }}"></script>
</body>
</html>
I am working on my code as I have got a list of checkboxes in the table. I have got a problem with adding the class in each row because it will only add one class in one row when I select all the checkboxes and click on a button.
Here is the checkboxes:
<tr class="read" data-id="236'" data-url="TTNsN1UxWXh5LzYwUjZaSlR1Qk4xZz09" data-sort="1556928960">
<td class="inbox-small-cells">
<div id="mail_checkbox" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox1" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="mail_check">Rob <myname#example.com></rob#example.com></div>
</td>
<td class="view-message">
<div id="mail_check">Hey!</div>
</td>
<td class="view-message inbox-small-cells">
<div id="mail_check"></div>
</td>
<td class="view-message text-right">
<div id="mail_check">04 May</div>
</td>
</tr>
<tr class="read" data-id="235'" data-url="U21hT0hpemZRUWlwUmN3amVjMUJzQT09" data-sort="1556479689">
<td class="inbox-small-cells">
<div id="mail_checkbox" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox1" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="mail_check">Shibbir <name2#example.com></creativeartbd#gmail.com></div>
</td>
<td class="view-message">
<div id="mail_check">Image in body and attachement</div>
</td>
<td class="view-message inbox-small-cells">
<div id="mail_check"><i class="fa fa-paperclip"></i></div>
</td>
<td class="view-message text-right">
<div id="mail_check">28 Apr</div>
</td>
</tr>
<tr class="read" data-id="234'" data-url="NWpoUGcwK1lIb2tJQWlzR0grQVhEUT09" data-sort="1556479271">
<td class="inbox-small-cells">
<div id="mail_checkbox" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox1" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="mail_check">Shibbir <name2#example.com></creativeartbd#gmail.com></div>
</td>
<td class="view-message">
<div id="mail_check">checking message body</div>
</td>
<td class="view-message inbox-small-cells">
<div id="mail_check"></div>
</td>
<td class="view-message text-right">
<div id="mail_check">28 Apr</div>
</td>
</tr>
I have tried this:
$(document).on('click','#Markasunread',function() {
alert("you are working on Markasunread now chris");
$("#mail_checkbox1").each(function() {
if ($(this).prop('checked') == true) {
$(".mail-check").prop("checked", false);
$("#select_all").prop("checked", false);
$(this).addClass("unread");
}
});
});
And I have also tried this:
$(document).on('click','#Markasunread',function() {
$("#mail_checkbox1").each(function() {
if ($(this).prop('checked') == true) {
$(".mail-check").prop("checked", false);
$("#select_all").prop("checked", false);
$(this).closest("tr").addClass("unread");
}
});
});
And this:
$(document).on('click','#Markasunread',function() {
$("#mail_checkbox1").each(function() {
if ($(this).prop('checked') == true) {
$(".mail-check").prop("checked", false);
$("#select_all").prop("checked", false);
$("#mail_checkbox1").closest("tr").addClass("unread");
}
});
});
What I am trying to achieve is when I select all the checkboxes and click on a button, I want to remove the class "read" and add the class "unread" in each row where the ticked checkboxes are.
Can you please show me an example how I could add the class for each row in the table where the ticked checkboxes are?
Thank you.
You arent allowed to use an ID more than once. So change the ID´s to a unique one.
Also try to use better JQuery Selectors. With "table input:checked" you´ll get all checked input fields inside your table. Now you can loop them to get the parent tr and add the unread class.
$('#actionButton').click(event => {
let inputs = $('table input:checked').toArray();
inputs.forEach(input => {
$(input).closest('tr').addClass('unread');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr class="read" data-id="236'" data-url="TTNsN1UxWXh5LzYwUjZaSlR1Qk4xZz09" data-sort="1556928960">
<td class="inbox-small-cells">
<div id="1_1" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox1" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="1_2">Rob
<myname#example.com>
</rob#example.com>
</div>
</td>
<td class="view-message">
<div id="1_3">Hey!</div>
</td>
<td class="view-message inbox-small-cells">
<div id="1_4"></div>
</td>
<td class="view-message text-right">
<div id="1_5">04 May</div>
</td>
</tr>
<tr class="read" data-id="235'" data-url="U21hT0hpemZRUWlwUmN3amVjMUJzQT09" data-sort="1556479689">
<td class="inbox-small-cells">
<div id="2_1" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox2" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="2_2">Shibbir
<name2#example.com>
</creativeartbd#gmail.com>
</div>
</td>
<td class="view-message">
<div id="2_3">Image in body and attachement</div>
</td>
<td class="view-message inbox-small-cells">
<div id="2_4"><i class="fa fa-paperclip"></i></div>
</td>
<td class="view-message text-right">
<div id="2_5">28 Apr</div>
</td>
</tr>
<tr class="read" data-id="234'" data-url="NWpoUGcwK1lIb2tJQWlzR0grQVhEUT09" data-sort="1556479271">
<td class="inbox-small-cells">
<div id="3_1" name="mail_checkbox">
<input type="checkbox" id="mail_checkbox3" name="mail_checkbox1" class="mail-check" unchecked="">
</div>
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">
<div id="3_2">Shibbir
<name2#example.com>
</creativeartbd#gmail.com>
</div>
</td>
<td class="view-message">
<div id="3_3">checking message body</div>
</td>
<td class="view-message inbox-small-cells">
<div id="3_4"></div>
</td>
<td class="view-message text-right">
<div id="3_5">28 Apr</div>
</td>
</tr>
</tbody>
</table>
<input type="button" id="actionButton" value="Change">
I having struggling for sometime to get this work!!!
I have a shopping cart created in laravel
This is the Shopping Cart image :
I want user to be able to edit the 'qty' field and 'update shopping cart' button should compute the item 'total' and final 'total' but I can't get to it work
here is my updatecart method;
public function updateCart(Request $request)
{
$cart = $request->session()->get('cart');
if(!$cart){
$cart = new Cart($cart);
}
$i = 0;
foreach($cart->items as $item){
$qty = $request->input($item['item']['id']);
$item['qty'] = $qty;
$item['total'] = $item['price'] * $qty;
$i++;
}
$cart->totalQty = array_sum($request->all());
$request->session()->put('cart', $cart);
//return $cart->items;
return redirect()->route('cart');
}
and my blade template;
<form method="post" action="{{route('updateCart')}}">
{{ csrf_field() }}
<table class="table table-hover">
<thead>
<tr>
<th class="text-center">Product</th>
<th class="text-center">Qty</th>
<th class="text-center">Rate</th>
<th class="text-center">Subtotal</th>
<th> </th>
</tr>
</thead>
<tbody>
#foreach($items as $item)
<tr>
<td class="col-sm-8 col-md-6 text-center">
<div class="media">
<a class="thumbnail pull-left" href="#"> <img class="media-object" src="{{asset('storage/'.$item['image'])}}" style="width: 100px; height: 72px;"> </a>
<div class="media-body">
<h4 class="media-heading">{{$item['item']['title']}}</h4>
</div>
</div>
</td>
<td class="col-sm-1 col-md-1" style="text-align: center">
<input type="number" class="form-control input-sm" name="{{$item['item']['id']}}" value="{{old($item['item']['id']) ? old($item['item']['id']) : $item['qty']}}">
</td>
<td class="col-sm-1 col-md-1 text-center">₦{{$item['price']}}</td>
<td class="col-sm-1 col-md-1 text-center"><strong>₦{{$item['total']}}</strong></td>
<td class="col-sm-1 col-md-1">
<a href="#"> <button type="button" class="btn btn-danger">
<span class="fa fa-remove"></span> Remove
</button>
</a>
</td>
</tr>
#endforeach
<tr>
<td> </td>
<td> </td>
<td>
<h3>Total</h3>
</td>
<td class="text-center">
<h3><strong>₦{{$total}}</strong></h3>
</td>
<td></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> <button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-shopping-cart"></span>Update shopping Cart
</button> </td>
<td>
<a href="/"> <button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-shopping-cart"></span> Continue Shopping
</button>
</a>
</td>
<td>
<a href={{route( 'checkout')}} class="btn btn-success" role="button">
Checkout <span class="glyphicon glyphicon-play"></span>
</a>
</td>
</tr>
</tbody>
</table>
</form>
Thank you in advance!
Edited:
please note I don't want to update the cart per item but the whole cart!
You can use session()->forget('cart') before inserting into you cart.
$cart = $request->session()->forget('cart');
if(!$cart){
$cart = new Cart($cart);
}
$i = 0;
foreach($cart->items as $item){
$qty = $request->input($item['item']['id']);
$item['qty'] = $qty;
$item['total'] = $item['price'] * $qty;
$i++;
}
$cart->totalQty = array_sum($request->all());
$request->session()->put('cart', $cart);
After removing insert again into cart. It will work in your scenario
Hope this helps
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm having trouble inserting a simple row into a mysql database.
My code is:
<?php
include("$_SERVER[DOCUMENT_ROOT]/riteshproject/config.php");
include('../config.php')
?>
<?php
if(isset($_POST['Add'])) {
$query1="INSERT INTO flatmaster(flat) VALUES ('123')";
mysql_query($query1);
}?>
<input type="Submit" name="Add" id="add" value="Add">
I want to insert the row into the flatmaster table when I click on submit.
my whole code is
<?php
include("$_SERVER[DOCUMENT_ROOT]/riteshproject/config.php");
include('../config.php') ?>
<?php
/*if(isset($_POST['Add'])) {
$aria=$_POST['area'];
$custname=$_POST['custname'];
$mob1=$_POST['mob1'];
$mob2=$_POST['mob2'];
$flatbunglo=$_POST['flatbungalo'];
$address=$_POST['address'];
$bhk=$_POST['bhk'];
$rent=$_POST['rent'];
$diposit=$_POST['diposit'];
$sqft=$_POST['sqft'];
$floor=$_POST['floor'];
$lift=$_POST['lift'];
echo $addquery="insert into propertymaster (area,custname,mob1,mob2,proptype,address,bhk,rent,diposit,sqft,floor,lift)
values ('$aria','$custname','$mob1','$mob2','$flatbunglo','$address','$bhk','$rent','$diposit','$sqft','$floor','$lift')";
mysql_query($addquery);
}*/
if(isset($_POST['Add'])) {
$query1="INSERT INTO flatmaster(flat) VALUES ('123')"; mysql_query($query1);
}
?> <!DOCTYPE html> <html lang="en"> <head> <title>Shree Shree Property,kolhapur</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.2/jquery.min.js"></script>
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 0;
border-radius: 0;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}
/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}
/* Set black background color, white text and some padding */
footer {
background-color: #555;
color: white;
padding: 15px;
}
/* On small screens, set height to 'auto' for sidenav and grid */
#media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;} .active { background-color: #00bfff; }
}
</style> </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="#">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>Home</li> <li class="current" id="dddd"><a href="../aboutus.php" >About
US</a></li> <li>Contact US</li>
<li>Add Property</li> <li>Luxarious Property</li> <li><a href="#">Property For
Sale</a></li> <li>Other Services</li>
</ul>
<ul class="nav navbar-nav navbar-right"> <li><a href="logout.php"><span class="glyphicon
glyphicon-log-in"></span>Logout</a></li>
</ul>
</div> </div> </nav> <div class="container-fluid text-center"> <div class="row content">
<div class="col-sm-2 sidenav">
<p>Link</p>
<p>Link</p>
<p>Link</p>
</div>
<div class="col-sm-8 text-left"> <html> <body> <div id="wrap2"> <form> <?php include("auth.php"); //include auth.php file on all
secure pages ?> <h4>Welcome Mr.<?php echo $_SESSION['username'];
?>!</h4> </form> <form> <html>
<body>
<table>
<tr>
<td width='100px' >
</td>
<td align="right">
Area:
</td>
<td style="text-align:left" width="100px">
<select name="area" id="area" value="select">
<option value="SELECT" style="display:none">SELECT</option>
<?php
$query="select code,areaname from areamaster";
$query_run=mysql_query($query);
mysql_num_rows($query_run);
while($row=mysql_fetch_assoc($query_run))
{
?>
<option value="<?php echo $row['code']?>"><?php echo $row['areaname']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr class="space1">
<td width='100px' >
</td>
<td align="right">
Customer Name:
</td>
<td>
<input type="text" id="custname" name="custname" size="40">
</td>
</tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Mobile No 1:
</td>
<td>
<input type="text" id="mob1" name="mob1">
</td>
</tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Mobile No 2:
</td>
<td>
<input type="text" id="mob2" name="mob2">
</td>
</tr>
<tr>
<td>
</td>
<td><b>FLAT DETAILS:</b>
</td>
</tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Flat/Bungalo:
</td>
<td>
<select name="flatbungalo" id="flatbungalo" value="select">
<option>Flat</option>
<option>Bungalo</option>
<option>House</option>
</select>
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Property Address:
</td>
<td><input type="text" id ="address" name ="address" size="40">
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
BHK:
</td>
<td>
<select name="bhk" id="bhk" value="select">
<option>1 BHK</option>
<option>2 BHK</option>
<option>3 BHK</option>
<option>4 BHK</option>
</select>
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
RENT:
</td>
<td><input type="text" id ="rent" name ="rent" size="10">
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Diposit:
</td>
<td><input type="text" id ="diposit" name ="diposit" size="10">
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
SQ Ft:
</td>
<td><input type="text" id ="sqft" name ="sqft" size="10">
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Floor:
</td>
<td><input type="text" id ="floor" name ="floor" size="10">
</td> </tr>
<tr>
<td width='100px' >
</td>
<td align="right">
Lift:
</td>
<td>
<select name="lift" id="lift" value="select">
<option>Yes</option>
<option>No</option>
</select>
</td> </tr>
<tr height="20">
</tr>
<tr>
<td>
</td>
<td>
</td> <td align="left"><form method="POST"><input type="Submit" name="Add" id="add" value="Add"></form>
</td> </tr>
</table> </html> </form> </div> </body> </html>
</div>
<div class="col-sm-2 sidenav">
<div class="well">
<p>ADS</p>
</div>
<div class="well">
<p>ADS</p>
</div>
</div> </div> </div>
<footer class="container-fluid text-center"> <p>Footer Text</p>
</footer>
</body> </html>
You need to wrap your submit button inside a form and use POST to send data:
<?php
if(isset($_POST['Add'])) {
$query1="INSERT INTO flatmaster(flat) VALUES ('123')";
mysql_query($query1);
}
?>
<form method="POST">
<input type="Submit" name="Add" id="add" value="Add">
</form>
Warning! Your code is vulnerable to SQL Injection Attacks! How do I prevent SQL Injection Attacks?