Limiting list output to 10 per page when using array_merge

7 posts by 3 authors in: Forums > CMS Builder
Last Post: June 28, 2011   (RSS)

Re: [8bit Gamer] Limiting list output to 10 per page when using array_merge

By Jason - September 29, 2010

Hi,

That's interesting. How many records do you have in each section?

If you could email your CMS login and FTP details to jason@interactivetools.com I can take a look and see what's going on.

Note: Only email this information, don't post it to the forum.

Thanks.
---------------------------------------------------
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] Limiting list output to 10 per page when using array_merge

By gadefgaertgqe - September 29, 2010 - edited: September 29, 2010

Hi Jason!

Thanks for replying.

I am not sure what you mean by how many records, sorry.

Details emailed :)

Re: [8bit Gamer] Limiting list output to 10 per page when using array_merge

By Jason - September 29, 2010

Hi Paul,

I took a look and actually the code is working correctly. This is what's happening.
You're taking records from 2 tables (national_sachs_news and test_sach_news). national_sachs_news has 3 records in it and test_sach_news has 1 record in it. In your code, you're telling it to limit it to 10 records per page. So since the tables each have less then 10 records, all of their records are being returned. These are the 4 records that appear on the page. If there were more than 10 records in one or both of those tables, then you would see multiple pages.

Another thing to keep in mind is that your merged array ($allRecords) will be both of your records. If they're limited to 10 per page each, that means that $allRecords could have up to 20 records in it. So if you only want a max of 10 records to appear on the page, you should limit each to 5 records per page.

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] Limiting list output to 10 per page when using array_merge

Hi Jason,

Let me start with DOH!

I was an idiot and should have seen that!

End of the office day and too much coffee.

Thanks for taking the time to look at it, and now I have made the changes it does indeed work fine.

Paul

Re: [Pixels & Beats] Limiting list output to 10 per page when using array_merge

By Mikey - June 25, 2011

I'm using array_merge similar to the code below for a photo gallery that generated by uploads from two separate multi section records. Using the code as it is with the 'perPage' => '4', before the array_merge takes place, makes too many images appear in the photo gallery based on the number of multi section articles posted and if an article is posted with only one photo, it leaves 3 empty table cells open in the photo gallery. Is it possible to limit the combine record photos displayed after the array_merge takes place as seen in the code in red?

// load records
list($national_newsRecords, $national_sachs_newsMetaData) = getRecords(array(
'tableName' => 'national_sachs_news',
'allowSearch' => '0',
//'perPage' => '4',
));


// Tip: $dealer_newsRecords, $dealer_newsMetaData are the array names!
list($dealer_newsRecords, $dealer_newsMetaData) = getRecords(array(
'tableName' => $final,
'allowSearch' => '0',
//'perPage' => '4',
));

// put all the records in one list
$allRecords = array_merge( $dealer_newsRecords, $national_newsRecords );
// limit merged records to a combine 8 per page
$allRecords = array_merge( $dealer_newsRecords, $national_newsRecords );
'perPage' => '8',

$allMetaData = array_merge( $dealer_newsMetaData, $national_newsMetaData );


// sort them by date
function createdDateCompareFunction($a, $b) { return -strcmp($a['createdDate'], $b['createdDate']); }
usort($allRecords, 'createdDateCompareFunction');


?>

Re: [zick] Limiting list output to 10 per page when using array_merge

By Jason - June 28, 2011

Hi,

The perPage option will only limit the number of record at the time the query takes place and can't be applied afterwards.

Another option would be to return everything and then do your pagination manually. Take a look at this post:
http://www.interactivetools.com/forum/gforum.cgi?post=88664#88664.

This is an example of doing pagination for a category section my using a for loop to access elements in the array. This should help get you started.

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/