-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
74 lines (68 loc) · 2.37 KB
/
Copy pathindex.php
File metadata and controls
74 lines (68 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once('init.php');
header('Content-type: text/html; charset=utf-8');
$limit = 100;
$pg_num = (int)($_GET['pg_num'] ? $_GET['pg_num'] : 1);
$limitstart = ($pg_num - 1) * $limit;
$products = db_load_object_list("SELECT * FROM products LIMIT $limitstart, $limit");
$count = db_load_field_array("SELECT COUNT(*) FROM products");
$count = $count[0];
$pages = floor($count / $limit);
?><!doctype html>
<html lang="en-US">
<head>
<title>Каталог - Тестовый магазин</title>
</head>
<body>
<table align="center" cellspacing="0" cellpadding="0">
<tr>
<td><h1>Каталог</h1></td>
<td align="right">
<a href="cart.php">Корзина (<?php echo $_SESSION['CART'] ? count($_SESSION['CART']) : 0; ?>)</a><br />
<a href="orders.php">Заказы</a>
</td>
</tr>
<tr>
<td colspan="2">
<?php if ($products) : ?>
<table border="1" cellpadding="5">
<tr>
<th>ID</th>
<th>Название</th>
<th>Цена</th>
<th>Корзина</th>
</tr>
<?php foreach ($products as $product) : ?>
<tr>
<td><?php echo $product->product_id; ?></td>
<td><?php echo $product->product_name; ?></td>
<td><?php echo $product->product_price; ?></td>
<td>
<form method="POST" action="">
<input type="hidden" name="action" value="upd_cart" />
<input type="hidden" name="product_id" value="<?php echo $product->product_id; ?>" />
<input type="number" style="width:50px;" min="0" step="1" name="quantity" value="<?php echo $_SESSION['CART'][$product->product_id] ? $_SESSION['CART'][$product->product_id] : 0; ?>" />
<button type="submit">В корзину</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<p align="center">Страница <?php echo $pg_num; ?> из <?php echo $pages; ?></p>
<p align="center">
<?php if ($pg_num > 1) : ?>
<a href="?pg_num=<?php echo $pg_num - 1; ?>"> ◄ Назад</a>
<?php endif; ?>
||
<?php if ($pg_num < $pages) : ?>
<a href="?pg_num=<?php echo $pg_num + 1; ?>">Вперед ►</a>
<?php endif; ?>
</p>
<?php else : ?>
<p align="center">Нет данных, <a href="db_restart.php">перезапустить базу</a></p>
<?php endif; ?>
</td>
</tr>
</table>
</body>
</html>