style span display block float left div overflow hidden style class Ta

 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
<style>
span {
display: block;
float: left;
}
div {
overflow: hidden;
}
</style>
<?
class Table {
protected $db, $user;
protected $dp = 8;
protected $size = [4, 4];
protected $table = array();
public function __construct($db, $user) {
$this->db = $db;
$this->user = $user;
}
public function fill() {
for ($y = 1; $y <= $this->size[1]; ++$y) {
for ($x = 1; $x <= $this->size[0]; ++$x) {
$table = '
<span style="width: %d; height: %d; background: url(%s) %dpx %dpx;"></span>
';
if ($slot = $this->find($x, $y)) {
$item = $this->db->query('SELECT * FROM items WHERE id = ' . $slot['item'] . ' LIMIT 1')->fetchArray();
$background = '?preview';
if(isset($_GET['preview'])){
$image = imagecreatefrompng('images/orientation/vertical/sword.png');
imagepng($image);
exit;
}
$shiftX = ($x - ($slot['orientation'] == 'vertical' ? $slot['x2'] : $slot['x1'])) * $this->dp;
$shiftY = ($y - ($slot['orientation'] == 'vertical' ? $slot['y2'] : $slot['y1'])) * $this->dp;
$this->table[$y][$x] = sprintf($table, $this->dp, $this->dp, $background, $shiftX, $shiftY);
}
else {
$background = 'images/slot.png';
$this->table[$y][$x] = sprintf($table, $this->dp, $this->dp, $background, 0, 0);
}
}
}
}
public function show() {
$this->fill();
for ($y = $this->size[1]; $y > 0; --$y) {
echo '<div>';
for ($x = 1; $x <= $this->size[0]; ++$x) {
echo $this->table[$y][$x];
}
echo '</div>';
}
}
public function find($x, $y) {
$stmt = $this->db->prepare('SELECT * FROM inventory WHERE user = :user AND :x >= MIN(x1, x2) AND MAX(x1, x2) >= :x AND :y >= MIN(y1, y2) AND MAX(y1, y2) >= :y LIMIT 1');
$stmt->bindValue(':user', $this->user, SQLITE3_INTEGER);
$stmt->bindValue(':x', $x, SQLITE3_INTEGER);
$stmt->bindValue(':y', $y, SQLITE3_INTEGER);
$result = $stmt->execute();
return $result->fetchArray();
}
}
$db = new SQLite3('database.sq3');
$Table = new Table($db, 1);
$Table->show();
?>