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 7061241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:27:00+00:00 2026-05-28T04:27:00+00:00

I need next & previous id record in database on Yii framework to make

  • 0

I need next & previous id record in database on Yii framework to make navigation buttons next and back ?

  • 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-28T04:27:00+00:00Added an answer on May 28, 2026 at 4:27 am

    I made a function to get those ids your looking for. I suggest you to declare it in the model:

    public static function getNextOrPrevId($currentId, $nextOrPrev)
    {
        $records=NULL;
        if($nextOrPrev == "prev")
           $order="id DESC";
        if($nextOrPrev == "next")
           $order="id ASC";
    
        $records=YourModel::model()->findAll(
           array('select'=>'id', 'order'=>$order)
           );
    
        foreach($records as $i=>$r)
           if($r->id == $currentId)
              return isset($records[$i+1]->id) ? $records[$i+1]->id : NULL;
    
        return NULL;
    }
    

    So to use it all you have to do do is this:

    YourModel::getNextOrPrevId($id /*(current id)*/, "prev" /*(or "next")*/); 
    

    It will return the corresponding id of the next or previous record.

    I didn’t test it, so give it a try and if something goes wrong please let me know.

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

Sidebar

Related Questions

I have a problem when i need to fetch the next & previous document
I need to create next and previous link urls here's a sample <a href=/calendar/2009/10/>previous</a>
I need to go through elements with previuous and next buttons. Here is HTML
I am using Prism 2, trying to add four navigation buttons (First Record, Last
I need to align two divs next to each other, so that each contains
In my next rails project I'm going to need blogging functionality. I'm wondering whether
i need a pop up window which asks me before proceeding to next like
I need to call a method I have defined as: -(IBAction)next:(id)sender{ ... } I
I have the next problem: I need to process only 1 request at a
I need replace slide effect to fade-out/fade-in effect on the prev and next slide

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.