orderBy question

9 posts by 3 authors in: Forums > CMS Builder
Last Post: December 12, 2013   (RSS)

By Jesus - December 4, 2013

Hi,

On my product details page, I want to display all my products order by title on my right side column. I'm using this code:

  // load records from 'sbs_espanol'
  list($sbs_espanolRecords, $sbs_espanolMetaData) = getRecords(array(
    'tableName'   => 'sbs_espanol',
    'loadUploads' => true,
    'orderBy'     => 'title',
    'allowSearch' => false,
  ));

But with no luck... Am I missing something on the orderBy?

Thanks for pointing me out to the right direction.

By zip222 - December 5, 2013

What you have appears to be correct. It's possible there is something else on your page that is preventing this from working properly. Can you post the full page code?

By Jesus - December 5, 2013

Hi zipp222

The code i'm using to display the products its

<ul class='left_navigation'>
   <?php foreach ($sbs_espanolRecords as $record): ?>
         <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
   <?php endforeach ?>
</ul>

Thanks!

By Dave - December 8, 2013

Hi Jesus, 

Can you try creating a simple page with just that viewer code and see if it works there?

If it doesn't, try adding this option to show the MySQL being used: 

'debugSql'           => true,

And this line after to show the records being returned:

showme($sbs_espanolRecords);

Let me know what happens, thanks!

Dave Edis - Senior Developer
interactivetools.com

By Jesus - December 9, 2013

Hi Dave,

Thanks for your help, I'm lost here :p

But I think I've an idea where's the problem here...

On my header i'm using this code... as I'm displaying the particular record, but at the same time, I'm loading all other records on the sidebar so, my code looks like this:

  // load record from 'sbs_espanol'
  list($sbs_espanolRecords, $sbs_espanolMetaData) = getRecords(array(
    'tableName'   => 'sbs_espanol',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $sbs_espanolRecord = @$sbs_espanolRecords[0]; // get first record
  if (!$sbs_espanolRecord) { dieWith404("Record not found!"); } // show error message if no record found
  

  // load records from 'sbs_espanol'
  list($sbs_espanolRecords, $sbs_espanolMetaData) = getRecords(array(
    'tableName'   => 'sbs_espanol',
    'loadUploads' => true,
    'orderBy'     => 'title',
    'allowSearch' => false,
  ));

As you can see, I'm loading 1st the record to display details and then, I load again all records from the same table to display on my sidebar,

Then, my sidebar code looks like this:

<ul class='left_navigation'>
<?php foreach ($sbs_espanolRecords as $record): ?>
    <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
<?php endforeach ?>
</ul>

The page its working fine but the only missing thing its that I want to have my sidebar with ordered products.

Thanks for your help!

By Jesus - December 12, 2013

Hi Dave,

Still no luck, my code looks now:

// load record from 'sbs_espanol'
  list($sbs_espanolRecords, $sbs_espanolMetaData) = getRecords(array(
    'tableName'   => 'sbs_espanol',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
));
$sbs_espanolRecord = @$sbs_espanolRecords[0]; // get first record
if (!$sbs_espanolRecord) { dieWith404("Record not found!"); } // show error message if no record found
  

// load records from 'sbs_espanol'
  list($sbs_espanolRecordsAllRecords, $sbs_espanolRecordsAllMetaData) = getRecords(array(
    'tableName'   => 'sbs_espanol',
    'loadUploads' => true,
    'orderBy'     => 'title',
    'allowSearch' => false,
));

and

<ul class='left_navigation'>
    <?php foreach ($sbs_espanolRecordsAllRecords as $record): ?>
          <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></li>
    <?php endforeach ?>
</ul>

It still display the product list but not ordered by Title :(

Any ideas? I'm sending you the complete file by email, probably will be easy for you to take a look at what I'm doing.

Thanks again for your help!

Jesus

By Jesus - December 12, 2013

Hi Dave,

Never mind, the code worked perfectly, it was a typo I had on it. Sorry, the list its now ordered!!

Thanks!

By Dave - December 12, 2013

Ok, great!  Glad it's working.  Cheers!

Dave Edis - Senior Developer
interactivetools.com