SHARE
TWEET

Untitled

a guest Feb 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $pullMapInfo = "SELECT x, y, z, value FROM mapinfo WHERE id='{$player_id}'";
  2.     $pullMapInfo2 = mysql_query($pullMapInfo) or die($error[4]);
  3.  
  4.     //create an array with all x, y, z
  5.     for ($y = 1; $y <= 16; $y++) $array_y[] = $y;
  6.     for ($x = 1; $x <= 16; $x++) $array_x[] = $x;
  7.     for ($z = 1; $z <= 3; $z++) $array_z[] = $z;
  8.  
  9.     //create an associative array x, y, z => value
  10.     $result_value = array();
  11.     while ( $pullMapInfo3 = mysql_fetch_assoc($pullMapInfo2) ) {
  12.         $result_value[ $pullMapInfo3['x'] ][ $pullMapInfo3['y'] ][ $pullMapInfo3['z'] ] = $pullMapInfo3['value'];
  13.     }
  14.  
  15.     //loop to display output
  16.     foreach ($array_z as $z) {
  17.         echo '<div class="container">';
  18.     foreach ($array_y as $y) {
  19.     foreach ($array_x as $x) {
  20.  
  21.         if (array_key_exists($x, $result_value) && array_key_exists($y, $result_value[$x] )) {
  22.             echo '<div class="tileBox pos_',$result_value[$x][$y][$z] ,'" id="'.$x.','.$y.','.$z.'"></div>';
  23.         } else {
  24.             echo '<div class="tileBox pos_0" id="'.$x.','.$y.','.$z.'"></div>
  25.     ';
  26.         }
  27.     }
  28.     }
  29.         echo '</div>';
  30.     }
  31.  
  32.     var_dump($result_value);
  33.     #outputs: array(1) { [1]=> array(1) { [1]=> array(1) { [1]=> string(1) "3" } } }
  34.     #as it pulled data from database: x, y, value - it misses z!
  35.    
  36. bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) ... x768 (16x16x3)
  37.    
  38. array(
  39.     [x=1] => array(
  40.        [y=1] => array(
  41.             [z=1] => "3"
  42.                      )
  43.                    )
  44.    
  45. $newarr[array_pop($arr)] = 0;
  46. foreach (array_reverse($arr) as $i)
  47.     $newarr[$i] = $newarr;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top