View difference between Paste ID: s9dPiJRX and 7B9cwagX
SHOW: | | - or go back to the newest paste.
1-
include_once 'connect.php';
1+
<?php
2
3-
$player_id = '6';
3+
    $db_host = '';
4
    $db_user = '';
5-
$result_value = array();
5+
    $db_password = '';
6
    $dbName = '';
7-
for ($ix = 1; $ix <= 16; $ix++) {
7+
8-
$result_value[$ix] = array();
8+
    $db = mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
9-
for ($iy = 1; $iy <= 16; $iy++) {
9+
    if(!$db) die(mysql_error());
10-
$result_value[$ix][$iy] = array();
10+
    if(!mysql_select_db($dbName,$db)) die(mysql_error());
11-
}
11+
12-
}
12+
    $player_id = 6;
13
14-
$pullMapInfo = "SELECT x, y, z, value FROM mapinfo WHERE id='{$player_id}'";
14+
    $arr3d = array();
15-
$pullMapInfo2 = mysql_query($pullMapInfo) or die(mysql_error());
15+
16-
$pullMapInfo3 = mysql_fetch_assoc($pullMapInfo2);
16+
    /* Initialization to get a "dense" array
17-
$x = $pullMapInfo3["x"];
17+
    $z_row = array_fill(0, $max_z, '<DEFAULT>');
18-
$y = $pullMapInfo3["y"];
18+
    $y_row = array_fill(0, $max_y, $z_row);
19-
$z = $pullMapInfo3["z"];
19+
    $arr3d = array_fill(0, $max_x, $y_row);
20
    unset($y_row, $z_row); // Do not waste memory
21-
$result_value[$x][$y][$z] = $pullMapInfo3["value"];
21+
    */
22
23-
for($iz = 1; $iz <= 3; $iz++){
23+
    $query = "SELECT x, y, z, value FROM mapinfo WHERE id='{$player_id}'";
24-
    echo 'Layer ', $iz, '<br>';
24+
25-
for($ix = 1; $ix <= 16; $ix++){
25+
    $handle = mysql_query($query) or die("$query: error: " . mysql_error());
26-
for($iy = 1; $iy <= 16; $iy++){
26+
27-
    $result_value[$x][$y][$z] = $pullMapInfo3["value"];
27+
    while($row = mysql_fetch_array($handle))
28-
    echo '<br>';
28+
    {
29-
}
29+
        // $row is an array with x, y, z and value keys in this order
30-
}
30+
        list($x, $y, $z, $value) = $row;
31-
}
31+
32
        /* This if we had used mysql_fetch_assoc instead
33
        $x = $row['x'];
34
        $y = $row['y'];
35
        $z = $row['z'];
36
        $value = $row['value'];
37
        */
38
        if (!isset($arr3d[$x]))
39
            $arr3d[$x] = array();
40
        if (!isset($arr3d[$x][$y]))
41
            $arr3d[$x][$y] = array();
42
        $arr3d[$x][$y][$z] = $value;
43
    }
44
    mysql_free($handle);