for ($x = 0; $x < $size[0]; ++$x) { for ($y = 0; $y < $size[1]; ++$y) { $_check = $db -> prepare('SELECT * FROM `table` where `x` = ? and `y` = ?'); $_check -> execute([$x,$y]); $check = $_check-> fetch(); $_items = $db -> prepare('SELECT * FROM `items` where `id` = ?'); $_items -> execute([$check['item']]); $item_check = $_items -> fetch(); if(check($x, $y, $check['rotation'], $width, $height, $x, $y) == true) echo 'TRUE!!!!!!!!!!!!!!!!!!!!!!!!!'; imagecopyresampled($basis, $slot, $x * $dp, $y * $dp, 0, 0, $dp, $dp, $slot_width, $slot_height); } }