001.
<?php
002.
session_start();
003.
$dbcon
= mysqli_connect(
"localhost"
,
"root"
,
"024211234"
,
"earth"
);
004.
?>
005.
<html>
006.
<head>
007.
<title>qweqweqweqwe</title>
008.
009.
010.
011.
012.
013.
<link href=
"vendor/bootstrap/css/bootstrap.min.css"
rel=
"stylesheet"
>
014.
015.
017.
</head>
018.
<body>
019.
<br />
020.
<div
class
=
"container"
style=
"width:800px;"
>
021.
<h3 align=
"center"
>MUUASDLJSK ASLDASJNCZ APDJ EE APSODJX C C AJSDKLAS</H3>
022.
<ul
class
=
"nav nav-tabs"
>
023.
<li
class
=
"active"
><a data-toggle=
"tab"
href=
"#products"
>Product</li>
024.
<li> <a data-toggle =
"tab"
href=
"#cart"
> Cart <span
class
=
"badge"
><?php
if
(isset(
$_SESSION
[
"shopping_cart"
])){
echo
count
(
$_SESSION
[
"shopping_cart"
]);}
else
{
echo
'0'
;}?></span> </a></li>
025.
026.
</ul>
027.
<div
class
=
"tab-content"
>
028.
<div id=
"products"
class
=
"tab-pane fde in active"
>
029.
<?php
030.
$sql
=
"SELECT * FROM stock ORDER BY idst ASC"
;
031.
$result
=mysqli_query(
$dbcon
,
$sql
);
032.
while
(
$row
= mysqli_fetch_array(
$result
))
033.
{
034.
?>
035.
<div
class
=
"col-md-4"
>
036.
<div
class
=
"thumbnail"
>
037.
038.
<div style=
"border:1px solid:#333; background-color:whit; border-radius:5px;padding:1px;margin:1px"
>
039.
<img src=
"img/<?php echo $row['pic']?> "
width=
"220px"
height=
"186px"
><br>
040.
<h4
class
=
"text-info"
><?php
echo
$row
[
"name"
];?></h4>
041.
<h4
class
=
"text-danger"
>฿ <?php
echo
number_format(
$row
[
"price"
],2);?>THB</h4>
042.
<input type=
"hidden"
name=
"hidden_name"
id=
"name<?php echo $row["
idst
"];?>"
value=
"<?php echo $row["
name
"];?>"
/>
043.
<input type=
"hidden"
name=
"hidden_price"
id=
"price<?php echo $row["
idst
"];?>"
value=
"<?php echo $row["
price
"];?>"
/>
044.
<input type=
"text"
name=
"quanlity"
id=
"quanlity<?php echo $row["
idst
"];?>"
class
=
"form-control"
value=
"1"
/>
045.
<input type=
"button"
name=
"add_to_cart"
id=
"<?php echo $row["
idst
"];?>"
class
=
"btn btn-success form-control add_to_cart"
value=
"Add to Cart"
/>
046.
</div>
047.
048.
</div>
049.
</div>
050.
<?php
051.
}
052.
?>
053.
<div id=
"cart"
class
=
"tab-pane fade"
>
054.
<div
class
=
"table-responsive"
id=
"order_table"
>
055.
<table
class
=
"table table-bordered"
>
056.
<tr>
057.
<th width =
"40%"
>Product Name </th>
058.
<th width =
"10%"
>Quanlity </th>
059.
<th width =
"20%"
>price</th>
060.
<th width =
"15%"
>Total </th>
061.
<th width =
"5%"
>Action</th>
062.
</tr>
063.
<?php
064.
if
(!
empty
(
$_SESSION
[
"shopping_cart"
]))
065.
{
066.
$total
= 0;
067.
foreach
(
$_SESSION
[
"shopping_cart"
]
as
$keys
=>
$values
)
068.
{
069.
070.
?>
071.
<tr>
072.
<td><?php
echo
$values
[
"product_name"
]; ?></td>
073.
<td><?php
echo
$values
[
"product_quanlity"
];?></td>
074.
<td align=
"right"
>$ <?php
echo
$values
[
"product_price"
]; ?></td>
075.
<td align=
"right"
>$ <?php
echo
number_format(
$values
[
"product_quanlity"
] *
$values
[
"product_price"
],2);?></td>
076.
<td><button name=
"delete"
class
=
"btn btn-dange btn-xs delete"
id=
"<?php echo $values["
product_id
"]; ?>"
>REMOVEEEE</button>
077.
</tr>
078.
079.
<?php
080.
$total
=
$total
+ (
$values
[
"product_quanlity"
] *
$values
[
"product_price"
]);
081.
}
082.
?>
083.
<tr>
084.
<td colspan=
"3"
align=
"right"
> Total </td>
085.
<td align =
"right"
> $ <?php
echo
number_format(
$total
,2);?></td>
086.
<td></td>
087.
</tr>
088.
</table>
089.
<?php
090.
}
091.
092.
?>
093.
094.
</div>
095.
096.
</div>
097.
</div>
098.
</div>
099.
</body>
100.
</html>
101.
<script>
102.
$(document).ready(
function
(data){
103.
$(
'.add_to_cart'
).click(
function
(){
104.
var
product_id = $(this).attr(
"idst"
);
105.
var
product_name= $(
'#name'
+product_id).val();
106.
107.
var
product_price = $ (
'#price'
+ product_id).val();
108.
var
product_quanlity = $(
'#quanlity'
+ product_id).val();
109.
110.
var
action =
"add"
;
111.
112.
if
(product_quanlity > 0)
113.
{
114.
$.ajax({
115.
url:
"action.php"
,
116.
method:
"POST"
,
117.
dataType:
"json"
,
118.
data :{
119.
120.
product_id:product_id,
121.
product_name:product_name,
122.
product_price:product_price,
123.
product_quanlity:product_quanlity,
124.
action:action
125.
126.
},
127.
success:
function
(data)
128.
{
129.
$(
'#order_table'
).html(data.order_table);
130.
$(
'.badge'
).text(data.cart_item);
131.
alert(
"prasdapsdka"
);
132.
}
133.
});
134.
}
135.
else
136.
{
137.
alert(
"req"
)
138.
}
139.
});
140.
141.
});
142.
</script>