-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththemes.php
More file actions
197 lines (146 loc) · 4.12 KB
/
themes.php
File metadata and controls
197 lines (146 loc) · 4.12 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
// Register for a Rebrickable account and palce your API key here
// https://rebrickable.com/api/
$key = '<REBRICKABLE_API_KEY>';
// The CSV files have been imported into the database
// THe API will be used for additional data
$connect = mysqli_connect(
'<DB_HOST>',
'<DB_USER>',
'<DB_PASSWORD>',
'<DB_DATABASE>'
);
function list_themes($parent_id = '')
{
global $connect;
$query = 'SELECT themes.id,
themes.name, (
SELECT COUNT(*)
FROM sets
WHERE sets.theme_id = themes.id
) AS sets, (
SELECT COUNT(*)
FROM themes AS subthemes
WHERE subthemes.parent_id = themes.id
) AS themes
FROM themes
WHERE themes.parent_id = "'.$parent_id.'"
ORDER BY themes.name';
$result = mysqli_query($connect, $query);
echo '<ul>';
while($record = mysqli_fetch_assoc($result))
{
echo '<li>';
echo '<a href="?theme='.$record['id'].'">'.$record['name'].'</a>';
echo '<br>
Themes: '.$record['themes'];
if($record['themes'])
{
list_themes($record['id']);
}
echo '<br>
Sets: '.$record['sets'];
if($record['sets'])
{
list_sets($record['id']);
}
echo '</li>';
}
echo '</ul>';
}
function list_sets($theme_id)
{
global $connect;
$query = 'SELECT sets.set_num,
sets.name,
sets.year,
sets.num_parts, (
SELECT COUNT(*)
FROM inventories
WHERE inventories.set_num = sets.set_num
) AS inventories, (
SELECT COUNT(*)
FROM inventory_sets
WHERE inventory_sets.set_num = sets.set_num
) AS inventory_sets
FROM sets
WHERE sets.theme_id = '.$theme_id.'
ORDER BY sets.year, sets.name
LIMIT 5';
$result = mysqli_query($connect, $query);
echo '<ul>';
while($record = mysqli_fetch_assoc($result))
{
echo '<li>';
echo '<a href="?set='.$record['set_num'].'">'.$record['name'].'</a>';
echo '<br>';
echo 'Parts: '.$record['num_parts'];
echo '<br>';
echo 'Year: '.$record['year'];
echo '<br>';
echo 'Inventories: '.$record['inventories'];
if($record['inventories'])
{
list_inventories($record['set_num']);
}
else echo '<br>';
echo 'Inventory Sets: '.$record['inventory_sets'];
if($record['inventory_sets'])
{
list_inventory_sets($record['set_num']);
}
echo '</li>';
}
echo '</ul>';
}
function list_inventories($set_num)
{
global $connect;
$query = 'SELECT inventories.set_num,
inventories.version
FROM inventories
WHERE inventories.set_num = "'.$set_num.'"
ORDER BY inventories.version';
$result = mysqli_query($connect, $query);
echo '<ul>';
while($record = mysqli_fetch_assoc($result))
{
echo '<li>';
echo 'Set: '.$record['set_num'].'</a>';
echo '<br>';
echo 'Version: '.$record['version'].'</a>';
echo '</li>';
}
echo '</ul>';
}
function list_inventory_sets($set_num)
{
global $connect;
$query = 'SELECT sets.set_num,
sets.name,
inventories.version,
inventory_sets.quantity
FROM inventory_sets
LEFT JOIN inventories
ON inventories.id = inventory_sets.inventory_id
LEFT JOIN sets
ON inventories.set_num = sets.set_num
WHERE inventory_sets.set_num = "'.$set_num.'"
-- ORDER BY inventory_sets.inventory_id';
$result = mysqli_query($connect, $query);
echo '<ul>';
while($record = mysqli_fetch_assoc($result))
{
echo '<li>';
echo 'Set: '.$record['set_num'].'</a>';
echo '<br>';
echo 'Name: '.$record['name'].'</a>';
echo '<br>';
echo 'Veraion: '.$record['version'].'</a>';
echo '<br>';
echo 'Quantity: '.$record['quantity'].'</a>';
echo '</li>';
}
echo '</ul>';
}
list_themes();