Displaying list view in columns
9 posts by 5 authors in: Forums > CMS Builder
Last Post: March 25, 2011 (RSS)
By _kate_ - June 8, 2008
Any help is appreciated :)
Re: [AgentBristow] Displaying list view in columns
By Dave - June 9, 2008
Try this code. It will output a </tr><tr> after every 2 <td>...</td> lines:
<table border="1">
<tr>
<?php foreach ($records as $record): ?>
<td>
<?php echo $record['title'] ?><br/>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach; ?>
</tr>
</table>
Note that you should use your own variable names instead of $record, etc but that the line in red can stay the same.
Let me know if that works for you.
interactivetools.com
Re: [Dave] Displaying list view in columns
I have the following code that displays a list of monthly downloads, all of which are arranged by year:
<?php $lastCategory = ''; ?>
<?php foreach ($services_building_statisticsRecords as $record): ?>
<?php if ($lastCategory != $record['title']): ?>
<h5>Monthly Building Statistics: <?php echo $record['title:label'] ?></h5>
<?php endif; ?>
<strong><span class="spanStats"><a href="<?php echo $record['content'] ?>" target="_blank"><?php echo $record['month'] ?></a> </span></strong>
<?php $lastCategory = $record['title']; ?>
<?php endforeach ?>
In this code "title" is the CMSB category for that shows the year.
Is there a way of displaying the months for each year in two rows/six columns?
This is the live page: http://www.wilmot.ca/departments-stats.php
Thanks,
Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net
Re: [NigelGordijk] Displaying list view in columns
By Jason - March 7, 2011
What you would need to do is to keep track of how many records you've outputted for each year. After you've outputted 6 for a given year, you can output a break (<br/>).
You'll need to make sure you reset this variable for each year.
Hope this helps get you started.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Dave] Displaying list view in columns
By csdesign - March 23, 2011
I have used this two column script before and it worked great so I don't know why it's fighting me so badly now. If you can tell me what I'm doing wrong I would really appreciate it!
This is the code I'm using and it's working - except for the fact that it only lists one physician name under each category then shoots the extras to the top of the page. I have my pre-column version at the bottom of the page. I have really tried working this out and I hope I'm not missing something really obvious.
list($specialtiesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'specialties',
));
// load records
list($physicians_wyomingRecords, $physicians_wyomingMetaData) = getRecords(array(
'tableName' => 'physicians_wyoming',
));
// organize physician records into specialties
$physicianSpecialityToRecord = array();
foreach( $physicians_wyomingRecords as $physician) {
// break selected specailties into an array
$specialties = explode("\t", trim($physician['specialties'], "\t"));
foreach ($specialties as $specialty){
$physicianSpecialityToRecord[$specialty][] = $physician;
}
}
and then the display code________________________
<table width="635" border="0">
<tr>
<?php foreach ($specialtiesRecords as $categoryRecord): ?>
<td>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php foreach ($physicianSpecialityToRecord[$categoryRecord['num']] as $physician): ?>
<a href="<?php echo $physician['_link'] ?>"><?php echo $physician['physician_first_name'] ?> <?php echo $physician['title'] ?></a>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr>
<?php endif; ?>
<?php endforeach ?>
<?php endforeach ?>
</tr>
</table>
http://www.nwsc5872139.myutilitydomain.com/physiciansList.php
_____________________________
I was also hoping to have the physician names bulleted (custom bullets or text bullets) other than having the category names... but I'm not sure where to even start with that.
_____________________________
Also, is it possible to direct the category links to the pages that are already setup for that category? For instance, when I click on Orthopedic, it goes to:
myutilitydomain.com/physiciansList.php?category=4
and I would prefer for it to go to:
myutilitydomain.com/orthopedic.php
Thanks so much for your help! Tina
Re: [csdesign] Displaying list view in columns
By Jason - March 24, 2011
I think the problem you're having with the formatting is you're incrementing your counter with each physician you're outputting, not each category. All we need to do to change that is to move our check outside the inner foreach loop. I also made a change in the code to output physicians as bulleted lists and changed the link for categories to go to orthopedic.php.
Take a look at the code below (changes in red):
<table width="635" border="0">
<tr>
<?php foreach ($specialtiesRecords as $categoryRecord): ?>
<td>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="orthopedic.php?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<ul>
<?php foreach ($physicianSpecialityToRecord[$categoryRecord['num']] as $physician): ?>
<li><a href="<?php echo $physician['_link'] ?>"><?php echo $physician['physician_first_name'] ?> <?php echo $physician['title'] ?></a></li>
<?php endforeach ?>
</ul>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>
</tr>
</table>
This should help get you in the right direction.
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/
Re: [Jason] Displaying list view in columns
By csdesign - March 24, 2011 - edited: March 24, 2011
Well, I'm about 10 steps closer. thank you!!
The only thing I can't quite figure out now is how to get the rest of the categories (specialties) to link to their own pages.
example:
Neurosurgery Spine -> neurosurgery_spine.php
Pumonlogy -> pulmonology.php
Right now they all go to orthopedic - understandable... I have another site that using similar category/link setup so I tried incorporating that and a few other things but none of it worked so I'm going to quit banging my head and break down and ask you. I'm sure it's in this part of the code (<a href="orthopedic.php?category=) but not sure how to make it play nice. I tried this modified version from my other site:
<a href="?specialties=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?> (<?php echo mysql_select_count_from('specialties',$where); ?>)</a>
Here's what have now:
<table width="635" border="0">
<tr>
<?php foreach ($specialtiesRecords as $categoryRecord): ?>
<td align="left" valign="top">
<h2><?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="orthopedic.php?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
</h2>
<?php foreach ($physicianSpecialityToRecord[$categoryRecord['num']] as $physician): ?>
<a href="<?php echo $physician['_link'] ?>"><img src="assets/bullet01-square.png" width="30" height="11" /><?php echo $physician['physician_first_name'] ?> <?php echo $physician['title'] ?></a><br />
<?php endforeach ?> <br /> </td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>
</tr>
</table>
Thank you!! Tina
Re: [csdesign] Displaying list view in columns
By Jason - March 25, 2011
What you can do here is to add a new field to your specialties section (something like "detail_page"). Then for each specialty, you can specify your which file you want it to go to (ie, pulmonology.php)
You can then output it like this:
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="<?php echo $category['detail_page'];?>?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
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/