<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
	require_once dirname(dirname(__FILE__)) . "/cmsAdmin/lib/viewer_functions.php";

  list($service_categoriesRecords, $service_categoriesMetaData) = getRecords(array(
    'tableName'   => 'service_categories',
  ));

  list($service_titlesRecords, $service_titlesMetaData) = getRecords(array(
    'tableName'   => 'service_titles',
	// 'limit'       => '8',
  ));

?>
<!--
Create an array of Service Categories, each one having a list of Service Titles inside them. 
First we create a list of Category Names based on Category Numbers from the service_categories table: 
-->
<?php   
 $categoryNumToName=array();  
 foreach($service_categoriesRecords as $category){     
 $categoryNumToName[$category['num']]=$category['category_name'];  }
?>

<!--
Next we create our array of Service Categories, based on the service_titles table like this: 
-->
<?php 
 $Services=array();    
 foreach($service_titlesRecords as $list){    
 $Services[$list['category']][]=$list['service_title'];  }
?>

<!--
The variable $Services, now holds all of the service titles, sorted by service_category. 

Now all we need is a nested foreach loop to display the information. For the purposes of an example, I'm outputting it as a nested list, but you can change this to output however you like: 
-->
<?php foreach($Services as $key=>$service): ?>   
<div id="menuServicesBox">
<?php if(is_array($service)): ?>          
    <h1><?php echo $categoryNumToName[$key];?> </h1>          
        <ul>         
			<?php foreach($service as $item): ?>             
            <li><?php echo $item ?></li> 
<?php endforeach ?>
			<li class="menuServicesBtn"><a href="page_name_tbd.php?service_categories=<?php echo $categoryNumToName[$key];?>" class="learnMoreLink">Learn More</a></li>        
        </ul>        
<?php endif ?> 
</div>
<?php endforeach ?>
