Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:00:46+00:00 2026-05-23T21:00:46+00:00

I have a list of ordered items, ordered according to the int field order

  • 0

I have a list of ordered items, ordered according to the int field order.
I’m creating a gallery in CakePHP 1.2 that has a prev and next button and those should link to the previous and next item according to their ordering, not according to their id.

In order to get this result I’ve included the ‘order’ parameter to the find function, and populated it with 'Item.order'=>'DESC'. Still the result is an id ordered list.

My question is: what do I do wrong?
My controller:

$this->Item->id = 16;

$neighbours = $this->Item->find('neighbors', array(
    'order' => array('Item.order'=>'DESC'),
    'fields' => array('id','name')
));

My Solution

I’ve tried a different approach. My code now does the job and looks as follows:

$order = $this->Item->findById(6);

$neighbours = $this->Item->find('neighbors', array(
    'field' => 'order',
    'value' => $order['Item']['order']
));

By setting the parameter 'field' to the field will be the ordering field, and set the 'value' parameter to the order value of you current Item you’ll get the prev and next.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:00:47+00:00Added an answer on May 23, 2026 at 9:00 pm

    Yeah the problem was that you weren’t including the order field in your fields array.

    $neighbours = $this->Item->find('neighbors', array(
        'order' => 'order DESC',
        'fields' => array('id', 'name', 'order')
    ));
    

    Unless you have related models with conflicting field names you don’t need to include the Item. model prefix (though I usually do anyway to avoid such errors.) You’re original syntax would work if you had included [Item.]order in “fields”

    Finally, your solution is not optimal, you’re making two SQL queries when you don’t need to. and ‘field’ is not a query option as far as I’m aware which actually means you’re returning all of the fields in the table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of un ordered items.In that list of items the clicked
I have this ordered List structure that has a structure that has two members,
I have a list of items that have a partial order relation , i.
I have list of items that need to be processed and printed to the
I have an ordered list, and each item has a link with class additem
I have a a simple ordered list that could contain 1 million or more
I have a List of items I call pages. Each page items has the
Say I have a list static list of Ids in a particular order: List<int>
I have collection of items and every of them has int TypeId property. I
I have an Ordered List which contains about 100 List Items. This ol makes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.