Get first record - change

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

By rjbathgate - June 2, 2009

Howdy,

On a list viewer, the standard code is:

list($servicesRecords, $servicesMetaData) = getRecords(array(
'tableName' => 'services',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$servicesRecord = @$servicesRecords[0]; // get first record


with the

$servicesRecord = @$servicesRecords[0]; // get first record

bit getting first record in table if there is no number on the end of URL.

Is there anyway to change this to say:

If no number on URL, get record where FIELD = 1

I.e. I can't rely on dragsortorder always being correct, so want to firmly set one record as first, based on that record having a checkbox value of 1.

Thanks in advance

Re: [rjbathgate] Get first record - change

By ross - June 3, 2009

Hi there.

Thanks for posting!

There is probably a way to do that but it will be a bunch of code. I am curious what you are trying to setup here. Perhaps there is a different approach :).

Basically, I am wondering why you would need to be going to your detail page without having a number at the end of your URL.

Let me know and we'll see what options there are going to be. 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: [ross] Get first record - change

By rjbathgate - June 3, 2009

Hey,

Cheers for the reply.

Basically the detail page also operates as the list page....

i.e. main nav in site goes to detailpage.php, and on that is subnav for all records (listpage style).

So, the mainnav goes to detailpage.php

And it's that detailpage.php instance in mainnav that I don't want to rely on dragsort order or fixed record num to pull up the record I want...

Hope that makes sense?!

Cheers
rob

Re: [rjbathgate] Get first record - change

By ross - June 4, 2009

Hi Rob

Thanks for the extra details. I see what you are doing there and to be honest, I think it might be a bit better if you used a separate list page and a separate detail page. That's the way the software was setup to work and you'll have a much easier time getting it all setup that way.

Having said that, if you really wanted (or needed) to stick with the one page approach, you'll probably want to switch the page to a listpage instead of a single page.

For the links from that to your "detail page", you would just pass the record number in the URL which would make your list page do a search and only show that one listing.

Let me know what you think and we'll go over all that in more detail.

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: [ross] Get first record - change

By rjbathgate - June 4, 2009

Hi Ross,

Thanks for the reply, we need to stick with the setup as it as present; I understand that the CMS was designed to operate with seperate list/detail, but I was really after any bespoke hack that would allow me to change the if no num in url, get record where...

Perhaps I can run an if statement, going IF no number in URL, then get record WHERE...

I'll try that

Thanks for ur help anyway,
Rob

Re: [rjbathgate] Get first record - change

By Dave - June 5, 2009

Hi Rob,

There's an undocumented feature where if there is no number in the url the whereRecordNumberInUrl() function uses what's in the brackets for the where. Try this:

list($servicesRecords, $servicesMetaData) = getRecords(array(
'tableName' => 'services',
'where' => whereRecordNumberInUrl(" FIELD = 1 "),
'limit' => '1',
));
$servicesRecord = @$servicesRecords[0]; // get first record


But replacing FIELD with your fieldname and 1 with the value you want to test for.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Get first record - change

By rjbathgate - June 8, 2009

Awesome, cheers Dave, that's a huge help - offers great potential too for some more stuff.

Cheers

Re: [Dave] Get first record - change

By InHouse - June 16, 2009

Oooh - neat! Just what I needed. Thanks for the Easter Egg Dave!
J.