Re: [hordak] Category List with Sub Items
Hi,
There are a couple of issues here, but they should be pretty easy fixes.
First, you need to change your code where you're creating $titleCount to this:
<?php
$titleCount=array();
foreach($as_humanities_faclistRecords as $title){
@$titleCount[$title['department']]++;
}
?>
The reason for this is that for each iteration of the loop, PHP takes 1 record from $as_humanities_faclistRecords and assigns it to $title.
Now, after that I'm seeing this line in your code:
<?php if (@$titleCount[$department['Africana Studies']]): ?>
This will cause an error because 'Africana Studies' is not a field name in the table.
We need to change this to the kind of values we were using when we created $titleCount, like this:
<?php if (@$titleCount[$department['department']]): ?>
Remember, in this case $department is just a record from $as_humanities_faclistRecords, not a table.
Finally, we need to change the variables that compare so that we skip records that are not in the proper category. So, our final code should look like this:
<?php
$titleCount=array();
foreach($as_humanities_faclistRecords as $title){
@$titleCount[$title['department']]++;
}
?>
<?php if ($as_humanities_faclistRecords): ?>
<div id="popup" style="display: none;"></div>
<?php foreach ($as_humanities_faclistRecords as $department): ?>
<?php if (@$titleCount[$department['department']]): ?>
<span class="text"><strong><?php echo $department['department'] ?></strong></span>
<?php endif ?>
<ul class="list" style="margin:2px;">
<?php foreach ($as_humanities_faclistRecords as $title): ?>
<?php if ($department['department'] != $title['department']) { continue; } // skip records which aren't in this category ?>
<li><?php echo $title['title'] ?></li>
<?php endforeach ?>
</ul>
<?php endforeach ?>
<?php endif ?>
Give this a try and let me know how it goes.
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/