global $mysqli;
$building = $position['buildingID'];
if($level == 'room') {
// Get building size
$buildingQuery = "SELECT * FROM buildings WHERE buildingID = '$building'";
$buildingArea = $mysqli->query($buildingQuery) or die(mysqli_error($mysqli));
$Area = $buildingArea->fetch_array(MYSQLI_ASSOC);
$AreaX = $Area['areaX'];
$AreaY = $Area['areaY'];
$sql = "SELECT * FROM rooms WHERE buildingID = '$building'";
$result = $mysqli->query($sql) or die(mysqli_error($mysqli));
$rooms = $result->fetch_array(MYSQLI_ASSOC);
for($y = 0; $y <= $AreaY; $y++){
for($x = 0; $x <= $AreaX; $x++) {
//See if room exists for coordinates
if(($rooms['position_x'] == $x) && ($rooms['position_y'] == $y)
&& ($position['room_x'] == $x) && ($position['room_y'] == $y)) {
echo '<img src="../../resources/images/inroom.php" id="'.$x.'_'.$y.'" />';
echo ' ';
} else if (($rooms['position_x'] == $x) && ($rooms['position_y'] == $y)) {
echo '<img src="../../resources/images/inroom.php" id="'.$x.'_'.$y.'" />';
echo ' ';
} else {
echo "(".$x.","." ".$y.")";
if ($x == $AreaX) {
echo '<br />';
}
}
}
}
}
}
基本上问题是我有一个网格系统,我需要显示坐标 X 和 Y 在数据库中对齐的结果集,但我真的不知道如何增加我正在检索的行,有什么建议吗?
编辑:代码更新