title: Create an multidimensional array from a database table
body: <p>I have a mysql table which contains is: </p>
  
  <pre><code>folder_id (int(11), auto increment) 
  folder_name (varchar) 
  folder_class(varchar) 
  folder_link (varchar)
  </code></pre>
  
  <p>What I want to do is somehow loop through the table and store each row like this:</p>
  
  <pre><code>$packs = array( array(  'Name'  =&gt; 'DarkUIPack', 
                      'Class' =&gt; 'ui',
                      'Link'  =&gt; 'http://graphicriver.net/item/dark-minimalist-ui-pack/662762' 
                  ),
              array(  'Name'  =&gt; 'MinimalistIcons', 
                      'Class' =&gt; 'min',
                      'Link'  =&gt; 'http://graphicriver.net/item/small-minimalist-icons-pack/670469'
                  ),
              array(  'Name'  =&gt; 'BlueMediaIcons', 
                      'Class' =&gt; 'blue',
                      'Link'  =&gt; 'http://graphicriver.net/item/blue-media-icons-set/705319'
                  ),
              array(  'Name'  =&gt; 'MediaIcons', 
                      'Class' =&gt; 'med',
                      'Link'  =&gt; 'http://graphicriver.net/item/media-icons-set/679835'
                  ),
              array(  'Name'  =&gt; 'ToTheTopButtons', 
                      'Class' =&gt; 'top',
                      'Link'  =&gt; 'http://graphicriver.net/item/to-the-top-buttons/673221'
                  ),
              array(  'Name'  =&gt; 'Sunglasses', 
                      'Class' =&gt; 'sun',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'RealEstate', 
                      'Class' =&gt; 'est',
                      'Link'  =&gt; 'http://graphicriver.net/item/simple-real-estate-logo/724697'
                  ),
              array(  'Name'  =&gt; 'PhotoStudio', 
                      'Class' =&gt; 'std',
                      'Link'  =&gt; 'http://graphicriver.net/item/photo-studio-logo/724694'
                  ),
              array(  'Name'  =&gt; 'PayDayCity', 
                      'Class' =&gt; 'std',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'MoleculeCorp', 
                      'Class' =&gt; 'mol',
                      'Link'  =&gt; 'http://graphicriver.net/item/molecule-corp-logo/719307'
                  ),
              array(  'Name'  =&gt; 'ClubbGX', 
                      'Class' =&gt; 'gx',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'AerialVision', 
                      'Class' =&gt; 'aer',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'ServiceCompany', 
                      'Class' =&gt; 'ser',
                      'Link'  =&gt; 'http://graphicriver.net/item/service-company-logo/727091'
                  ),
              array(  'Name'  =&gt; 'ElectroTech', 
                      'Class' =&gt; 'ele',
                      'Link'  =&gt; 'http://graphicriver.net/item/electro-tech-logo/720904'
                  ),
              array(  'Name'  =&gt; 'CreativeStudio', 
                      'Class' =&gt; 'cre',
                      'Link'  =&gt; 'http://graphicriver.net/item/creative-studio-logo/719494'
                  ),
              array(  'Name'  =&gt; 'NanoCorp', 
                      'Class' =&gt; 'nan',
                      'Link'  =&gt; 'http://graphicriver.net/item/nano-corp-logo/719098'
                  ),
              array(  'Name'  =&gt; 'RehabPlace', 
                      'Class' =&gt; 'reh',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'MyLocalMix', 
                      'Class' =&gt; 'mix',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'SevenBySeven', 
                      'Class' =&gt; 'sev',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'ComingSoon', 
                      'Class' =&gt; 'com',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'AlienIcons', 
                      'Class' =&gt; 'aln',
                      'Link'  =&gt; 'http://graphicriver.net/item/alien-icons-set/698515'
                  ),
              array(  'Name'  =&gt; 'PreloaderPortfolio', 
                      'Class' =&gt; 'pre',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'BioTech', 
                      'Class' =&gt; 'bio',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'ConstructionCompany', 
                      'Class' =&gt; 'con',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'EagleMedia', 
                      'Class' =&gt; 'egl',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'ElectronicWays', 
                      'Class' =&gt; 'elw',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'EnvironmentalCompany', 
                      'Class' =&gt; 'env',
                      'Link'  =&gt; ''
                  ),
              array(  'Name'  =&gt; 'SecureData', 
                      'Class' =&gt; 'sec',
                      'Link'  =&gt; 'http://graphicriver.net/item/secure-data-company-logo/907334'
                  ),
              array(  'Name'  =&gt; 'ConstructSimple', 
                      'Class' =&gt; 'cns',
                      'Link'  =&gt; 'http://graphicriver.net/item/simple-construction-company-logo/907538'
                  ),
              array(  'Name'  =&gt; 'ConstructRoof', 
                      'Class' =&gt; 'cnr',
                      'Link'  =&gt; 'http://graphicriver.net/item/construction-company-logo/907549'
                  )
          );  
  </code></pre>
  
  <p>where 'Name' corresponds to folder_name, 'Class' to folder_class and 'Link' to folder_link. </p>
  
  <p>I'm using this within a class and the class looks like this till now:</p>
  
  <pre><code>class folder
  {
  private $connect;
  
  public function __construct() {
  
      $this-&gt;connect = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  
      if (mysqli_connect_errno()) {
          $error = true;
          $message['error'] = true;
          $message['message'] = mysqli_connect_error();
          return json_encode($message);
      }
          else {
              return true;    
          }
  
  }
  
      public function crtFolder($fldName,$fldClass,$fldLink,$fldPath) {
  
      $fldName = preg_replace('/\s+/', '', $fldName);
  
      $fldPN = $fldPath."\\".$fldName;
  
      $modArray = array(array('1'));
  
      if ((!is_dir($fldPN))) {
          if(mkdir($fldPN,0777,true)) {
  
              $sql = "INSERT INTO folders (folder_name,folder_class,folder_link) VALUES (?, ?, ?)";
  
              if($stmt = $this-&gt;connect-&gt;prepare($sql)) {
                  $stmt-&gt;bind_param("sss", $fldName, $fldClass, $fldLink);
                  $stmt-&gt;execute();
                  $stmt-&gt;close();
                  $error = false;
                  $message['error'] = false;
                  $message['message'] = "Folder Created | Data Successfuly Inserted";
                  return json_encode($message);
              }
                  else {
                      $error = true;
                      $message['error'] = true;
                      $message['message'] = "Folder Created | Data Failed To Insert";
                      return json_encode($message);
                  }
          }
              else { 
                  $error = true;
                  $message['error'] = true;
                  $message['message'] = "Folder Failed To Create";
                  return json_encode($message); 
              }
      }
          else {
              $error = true;
              $message['error'] = true;
              $message['message'] = "Folder Already Exists";
              return json_encode($message);   
          }
  }
  
  public function __destruct() {
  
      $closeConnection = $this-&gt;connect-&gt;close();
  
      if($closeConnection) {
          return true;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm showing the class because I want to keep the same method for the creating the array as the other methods are created. Because I found something on Google, but it was making an array from multiple tables. I only have one table.</p>