Start Records from

8 posts by 3 authors in: Forums > CMS Builder
Last Post: August 2, 2011   (RSS)

By bashful - July 30, 2011

Hi,

I hope someone can help me. I want to beable to start showing the records from say 3 onwards rather than from the beginning.

I currently have per page limit set to 10 as shown below but not shure how to start showing records from 3. (1 and 2 are not shown).

ist($archived_articlesRecords, $archived_articlesMetaData) = getRecords(array(
'tableName' => 'archived_articles',
'perPage' => '10',
));

Many Thanks for your help

Re: [bashful] Start Records from

By Jason - July 30, 2011

Hi,

If you just want to show 10 records, skipping the first 2, you can try this:

ist($archived_articlesRecords, $archived_articlesMetaData) = getRecords(array(
'tableName' => 'archived_articles',
'offset' => 2,
'limit' => 10,
));


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] Start Records from

By bashful - July 30, 2011

Hi Jason,

Thanks for your reply - I wanted to keep the per page part - when I add the offset bit - it says canot use per page limit offset - I need to choose one.

Basically I have a home page where I only want to show the first 3 records and then I have a blog page and I want to show all records but start from the 4th record on wards.

I hope this makes sense.

Cheers

Re: [bashful] Start Records from

By robin - August 1, 2011

Hey,

Here is a possible solution This is using a where statement with a subquery. The subquery is there to remove the first 3 results. This is assuming you're ordering by createdDate, you may have to change the order by field.

list($archived_articlesRecords, $archived_articlesMetaData) = getRecords(array(
'tableName' => 'archived_articles',
'perPage' => '10',
'where' => "num NOT IN(SELECT num FROM " . getTableNameWithPrefix('archived_articles') . " ORDER BY createdDate)"
));


Hope that helps, let me know if you have any questions.

Robin
Robin
Programmer
interactivetools.com

Re: [robin] Start Records from

By bashful - August 1, 2011

Hi Robin,

Thanks for the reply - when I insert the where statement it shows the records as empty - do I insert the value 3 anywhere ?

Cheers

Re: [bashful] Start Records from

By robin - August 1, 2011

Hey,

Yes you're right I forgot to add the limit statement. In testing I found out that I needed to reword it a bit to get around a mysql limitation. Hopefully this one is more useful for you:

list($archived_articlesRecords, $archived_articlesMetaData) = getRecords(array(
'tableName' => 'archived_articles',
'perPage' => '10',
'where' => "num NOT IN(SELECT subTable.num FROM (SELECT num FROM " . getTableNameWithPrefix('archived_articles') . " ORDER BY createdDate LIMIT 3) subTable)",
));


Robin
Robin
Programmer
interactivetools.com

Re: [robin] Start Records from

By bashful - August 1, 2011

Hi Robin,

Many Thanks - that worked (the first 3 posts were removed), however as I use this page as a blog and when the posts are added, the most recent ones are shown on top.

Is there a way for me to have it so that the last 3 posts are omitted rather than the first 3 -.

Many Thanks