Display first record in the table by default, no matter what the recordNum?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 17, 2008   (RSS)

Re: [dougdrury] Display first record in the table by default, no matter what the recordNum?

By Dave - March 15, 2008

Hi Doug,

No problem, there's two things we can do. First, we get rid of that "getUploads" error. We actually added extra code for that in v1.06. Just add this around your getUploads code:

<?php if ($record): ?>

<?php foreach (getUploads ... ): ?>
...
<?php endforeach ?>

<?php endif ?>


That way, if no record is loaded (for whatever reason) it won't try to load the uploads for a record that isn't there and get an error.

Next, you want to always have your page viewer (which is on the same page) display the first record in the list. As long as the viewer code for the list viewer comes first in the page source code, we can do that like this:

$options['recordNum'] = @$listRows[0]['num'];

The $listRows is just a list of records, so the [0] gets the first one (PHP starts counting at zero) and ['num'] is the fieldname we want. The @ in front means "hide any errors if this variable isn't defined".

Hope that helps! Let me know how it goes!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Display first record in the table by default, no matter what the recordNum?

By dougdrury - March 17, 2008

Dave,
Thanks for the info on the getUploads. I will upadate my pageviewer code with that foreach.

As far as the listviewer/pageviewer issue...
This is so close to what I want... with one thing... (of course huh?)

If the page (with listviewer and pageviewer code onit) gets loaded without any number at the end of the URL, I want the first record to display in the page viewer (I won't know the record number since it could be brand new), but then if someone clicks on a link in the page list, I want that other page (the record num in the url) to be displayed by the page viewer. I tried the code you sent, but it always displays the first record even if the url has a record number in it.

Is there a way to test if the URL has a record num in it and if not, use the @$listRows[0]['num'] ?

Am I making any sense? [:/]

Re: [dougdrury] Display first record in the table by default, no matter what the recordNum?

By Dave - March 17, 2008

>Is there a way to test if the URL has a record num in it and if not, use the @$listRows[0]['num']?

Sure, try this instead (it's a few more lines):

$firstRecordNum = @$listRows[0]['num'];
$numOnEndOfUrl = getNumberFromEndOfUrl();
if ($numOnEndOfUrl) { $options['recordNum'] = $numOnEndOfUrl; }
else { $options['recordNum'] = $firstRecordNum; }


Let me know if that does what you need.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Display first record in the table by default, no matter what the recordNum?

By dougdrury - March 17, 2008

PERFECTO!
That worked like a champ!

Thank you sir!
~ Doug