<?php

// ***********************
// *                     *
// *  Get Filter Data  *
// *                     *
// ***********************

function get_filter_data() {
  include ("db_connection.php");

  $query = "SELECT t.type AS category, " .
                   "GROUP_CONCAT(DISTINCT category ORDER BY sort_order ASC) AS subcategory " .
               "FROM categories c, types t " .
               "WHERE c.type=t.type " .
               "GROUP BY t.type " .
               "ORDER BY t.type ASC";

  $result = $bwb_wiz_dbh->query($query);
  $rows = $result->fetchALL(PDO::FETCH_ASSOC);

  foreach ($rows as &$row) {

    if (is_string($row['category'])) {
      $row['subcategory'] = explode(',', $row['subcategory']);
    }
  }
/*
print "<pre style=\"text-align:left;\">";
print_r($rows);
print "</pre>";
*/

  return $rows;
}

?>