Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 13th, 2012  |  syntax: PHP  |  size: 1.25 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.     $db_host = '';
  4.     $db_user = '';
  5.     $db_password = '';
  6.     $dbName = '';
  7.  
  8.     $db = mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
  9.     if(!$db) die(mysql_error());
  10.     if(!mysql_select_db($dbName,$db)) die(mysql_error());
  11.  
  12.     $player_id = 6;
  13.  
  14.     $arr3d = array();
  15.  
  16.     /* Initialization to get a "dense" array
  17.     $z_row = array_fill(0, $max_z, '<DEFAULT>');
  18.     $y_row = array_fill(0, $max_y, $z_row);
  19.     $arr3d = array_fill(0, $max_x, $y_row);
  20.     unset($y_row, $z_row); // Do not waste memory
  21.     */
  22.  
  23.     $query = "SELECT x, y, z, value FROM mapinfo WHERE id='{$player_id}'";
  24.  
  25.     $handle = mysql_query($query) or die("$query: error: " . mysql_error());
  26.  
  27.     while($row = mysql_fetch_array($handle))
  28.     {
  29.         // $row is an array with x, y, z and value keys in this order
  30.         list($x, $y, $z, $value) = $row;
  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);
clone this paste RAW Paste Data