php include_once pdo class php db DB getInstance function dd var echo

  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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
include_once 'pdo.class.php';
$db = DB::getInstance();
function dd($var)
{
echo '<pre>';
var_dump($var);
echo '</pre>';
}
function type_name($key)
{
$array = [
'material' => 'Материал',
'type' => 'Тип поверхности',
'color' => 'Цвет',
'length' => 'Длина, м ',
'price' => 'Цена, руб/м2',
];
return $array[$key];
}
echo '
<style>
table, tr, td {
border: black solid 1px;
}
</style>
<br />
<table>
';
$product['id'] = 1;
$products_manufacturers = $db->query('
SELECT `products_manufacturers`.*, `manufacturers`.name AS `manufacturer_name` FROM `products_manufacturers`
LEFT JOIN `manufacturers` ON (`manufacturers`.id = `products_manufacturers`.manufacturer_id)
WHERE `product_id` = ? GROUP BY `products_manufacturers`.`manufacturer_id`, `products_manufacturers`.`id`
', [$product['id']])->fetchAll();
$data = [];
foreach ($products_manufacturers as $product_manufacturer) {
$json_data = json_decode($product_manufacturer['data'], true);
foreach ($json_data as $key => $value) {
$data[$key][] = ['value' => $value, 'id' => $product_manufacturer['id'], 'manufacturer_name' => $product_manufacturer['manufacturer_name']];
}
}
$keys = array_keys($data);
$count = count($keys);
$manufacturers = [];
foreach ($keys as $key) {
$manufacturers[$key] = '-';
}
$serialize_data = [];
foreach ($data as $key => $_value) {
foreach ($_value as $value) {
$serialize_data[$value['manufacturer_name']][$value['id']] = $manufacturers;
}
}
foreach ($data as $key => $_value) {
foreach ($_value as $value) {
$serialize_data[$value['manufacturer_name']][$value['id']][$key] = $value['value'];
}
}
echo '
<tr>
';
foreach ($keys as $value) {
echo '
<td>' . type_name($value) . '</td>
';
}
foreach ($serialize_data as $manufacturer => $products) {
echo '
<tr>
<td colspan="' . $count . '">' . $manufacturer . '</td>
</tr>
</tr>
';
foreach ($products as $product) {
echo '
<tr>
';
foreach ($product as $value) {
echo '
<td>' . $value . '</td>
';
}
echo '
</tr>
';
}
}
echo '
</table> count:
';
//{"material":"\u041f\u0412\u0425","type":"\u041c\u0430\u0442\u043e\u0432\u044b\u0439","color":"\u0411\u0435\u043b\u044b\u0439","length":"1,5-3,2","price":"\u043e\u0442 330"}
echo $db->countQuery;
?>