Re: [studio-a] Filtering one most recent record per category
Hi,
I think this may work for you. (Note: you may need to change some names to match what you have in your database or in your .php file)
What we need to do is to 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:
$categoryNumToName=array();
foreach($categoryRecords as $category){
$categoryNumToName[$category['num']]=$category['category_name'];
}
Next we create our array of Service Categories, based on the Service_Title table like this:
$Services=array();
foreach($listingsRecords as $list){
$Services[$list['category']][]=$list['service_name'];
}
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): ?>
<?php if(is_array($service)): ?>
<ul>
<li><?php echo $categoryNumToName[$key];?></li>
<ul>
<?php foreach($service as $item): ?>
<li><?php echo $item ?></li>
<?php endforeach ?>
</ul>
</ul>
<?php endif ?>
<?php endforeach ?>
Give this a try and let me know if it looks like this would work for you. If you run into any issues, please attach the .php file you're working with so I can take a closer look.
Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/