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

I am trying to get the data from the List view page to display in a table in 2 columns - I tried some of the codes in some of the other threads however I couldn't get these to work.

Any help is appreciated :)

Re: [AgentBristow] Displaying list view in columns

By Dave - June 9, 2008

No problem. The trick with any kind of design you want to create is to first create a mockup, then to figure out what the pattern is.

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.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Displaying list view in columns

By _kate_ - June 23, 2008

Worked perfectly! Thanks! :)

Re: [Dave] Displaying list view in columns

Hi, Dave.

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>&nbsp;&nbsp;&nbsp;&nbsp;</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,
Nigel Gordijk

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

Hi Nigel,

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: [csdesign] Displaying list view in columns

By Jason - March 24, 2011

Hi Tina,

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'] ?>&nbsp;<?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

Hi Jason,

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'] ?>&nbsp;<?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

Hi Tina,

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/