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

By NigelGordijk - March 3, 2011

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

By csdesign - March 23, 2011

Hi Dave,

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

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: [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/