using php to build map grid string -
i'm using pp3diso build game map. library uses string determine image use in each grid cell this: 01,01,01,01,01,01,01:02,01,01,01,01,01,01:01,01,01,01,01,01,01:01,01,01,01,01,01,01:01,01,01,01,01,01,01:01,01,01,01,01,01,01. i'm trying piece type of string in php while loops, code seems stop after first iteration (01,01,01,01,01,01,01,01:). how can code below create full string?
$mapstr = ''; $x = 1; $y = 1; while($x <= 500){ while($y <= 500){ $sql = 'select * '.cities.' city_x = '.$x.' , city_y = '.$y; $result = $db->sql_query($sql); $city = $db->sql_fetchrow($result); if($city){ $mapstr .= '02'.(($x < 500) ? ',' : ''); }else{ $mapstr .= '01'.(($x < 500) ? ',' : ''); } $y++; } if($x == 500){ $mapstr .= ':'; }else if($x == 500 && $y == 500){ $mapstr .= ''; } $x++; } $return['map'] = $mapstr; also, there more efficient way of doing instead of querying database each cell?
turned out easier in for loop:
$columns = 501; $rows = 501; for($x = 1; $x < $columns; $x++){ for($y = 1; $y < $rows; $y++){ $sql = 'select * '.cities.' city_x = '.$x.' , city_y = '.$y; $result = $db->sql_query($sql); $city = $db->sql_fetchrow($result); if($city){ $mapstr .= '02'; }else{ $mapstr .= '01'; } if($y < 500){ $mapstr .= ','; }elseif($y == 500){ $mapstr .= ':<br />'; } } $sql = 'select * '.cities.' city_x = '.$x.' , city_y = '.$y; $result = $db->sql_query($sql); $city = $db->sql_fetchrow($result); if($city){ $mapstr .= '02'; }else{ $mapstr .= '01'; } if($y < 500){ $mapstr .= ','; }elseif($y == 500){ $mapstr .= ':<br />'; } } echo $mapstr;
Comments
Post a Comment