Do not show first record

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 1, 2012   (RSS)

Hi Guys,

There's probably a very simple way to action this...

I've got a combo page, with a side navigation (list) of stores, and a main div of the store details. The file is stores.php.

If I load this page, because there is no ?title-31 , it shows the first record.

Is it possible to say "if no record selected, show ..."

Thanks!
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Do not show first record

Hi,

I think the easiest way to solve this problem is to use a where statement in your getRecords function and get the page num value from the URL manually. Then if there is no number in the URL you can set getRecord to pull whatever record you want as the default. I would do something like this:

//This function gets the last number from the URL. If there is no number it will return 0;
$number = getLastNumberInUrl();
//This if statement will set the $number variable to the number 3 if it is currently less than 1. Change the number 3 to whatever record you want to load.
$number = ($number < 1)? '3' : $number;

//This getRecords function uses a where statement to pull correct record from a table. Make sure allowSearch is set to false or you could run into problems.
list($mainContents, $test_1MetaData) = getRecords(array(
'tableName' => 'test_1',
'where' => "`num` = '$number'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$mainContent = @$mainContents[0]; // get first record


Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [Toledoh] Do not show first record

This is fairly straight forward as well. I'd just add a second variable that is true or false if $number equals zero then you can use it for displaying custom code on the page.

//This function gets the last number from the URL. If there is no number it will return 0;
$number = getLastNumberInUrl();
//This if statement will set the $number variable to the number 3 if it is currently less than 1. Change the number 3 to whatever record you want to load.
$nothingSelected = ($number < 1)? true : false;
$number = ($number < 1)? '3' : $number;


//This getRecords function uses a where statement to pull correct record from a table. Make sure allowSearch is set to false or you could run into problems.
list($mainContents, $test_1MetaData) = getRecords(array(
'tableName' => 'test_1',
'where' => "`num` = '$number'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$mainContent = @$mainContents[0]; // get first record


?>

<?php if($nothingSelected): ?>
<p>I'm sorry, you need to select something from the left. <p>
<?php else: ?>
<!-- Main Content goes in here -->
<?php endif ?>

Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Do not show first record

By Toledoh - October 1, 2012

Brilliant!
Cheers,

Tim (toledoh.com.au)