How to split listing records

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 16, 2009   (RSS)

By rebjr - April 15, 2009

I'm having trouble figuring out how to list half of the records in one div and the other half in another div, sorted by the dragSortOrder. I have the basics working, but I'm using 'num' to get at the records and as a result it's not using the drag order sort. Here's the code I have now for that:
list($practice_areasRecords, $practice_areasMetaData) = getRecords(array(
'tableName' => 'practice_areas',
'loadUploads' => '0',
'allowSearch' => '0',
));

// Get number of records to use below when displaying in columns
$count = $practice_areasMetaData['totalRecords'];
$half = $count/2;
$firsthalf = ceil($count/2);


Later on the page I show the records:

<div class="firstColumn">
<ul>
<?php
$desired_num = $firsthalf; // Show the first half of the records
foreach ($practice_areasRecords as $record):
if ($record['num'] <= $desired_num ) {
?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php
}
endforeach;
?>
<?php if (!$practice_areasRecords): ?>
<li>No records were found!</li>
<?php endif ?>
</ul>
</div>

<div class="secondColumn">
<ul>
<?php
$desired_num = $firsthalf; // Use to show the rest of the records
foreach ($practice_areasRecords as $record):
if ($record['num'] > $desired_num ) {
?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php
}
endforeach;
?>
<?php if (!$practice_areasRecords): ?>
<li>No records were found!</li>
<?php endif ?>
</ul>
</div>


What I'd like to do is query the database and get all the records, get the total count, and then show the first half in the first column and the rest in the second column using some sort of counter so I can be sure to use the dragSortOrder and not the 'num' order. Any examples of doing this? Thanks.

Re: [rebjr] How to split listing records

By ross - April 16, 2009

Hi there

Thanks for posting!

Do both your <div> blocks need to be right next to one another in the code (not nessesarily displayed next to one another). Or would they be in different places of the code?

Also, do you have a sample mockup of the page so I can have a look at it?

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [Dave] How to split listing records

By rebjr - April 16, 2009

I ended up solving it this way, using dragSortOrder as an index into the array:

<div class="span-3 append-1">
<ul>
<?php
$desired_num = $firsthalf; // Show the first half of the records
foreach ($practice_areasRecords as $record):
if ($record['dragSortOrder'] >= $desired_num ) {

?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php
}
endforeach;
?>
<?php if (!$practice_areasRecords): ?>
<li>No records were found!</li>
<?php endif ?>
</ul>
</div> <!-- // .span-3 append-1 -->

<div class="span-3">
<ul>
<?php
$desired_num = $firsthalf; // Use to show the rest of the records
foreach ($practice_areasRecords as $record):
if ($record['dragSortOrder'] < $desired_num ) {

?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php
}
endforeach;
?>
</ul>
</div> <!-- // .span-3 -->