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 Dave - December 12, 2013

Hi Jesus, 

The code looks right, the next thing I'd suggest is to use a different variable name for the second time you are loading $sbs_espanolRecords so it's clear which is which and you're not overwriting variables.  Perhaps call it: $sbs_espanolRecordsAll since it contains "all" the records.

And update your sidebar to list all the records from $sbs_espanolRecordsAll as well.

Let me know if that works for you or any other issues you run into. 

Thanks!

Dave Edis - Senior Developer
interactivetools.com

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