Skip to content
Advertisement

How to get next and previous id on CodeIgniter3?

I have the following DB.

JavaScript

As you can see, the ID is missing a tooth.

so you cannot get a valid previous or next ID by simply adding or subtracting 1 to the current ID

In SQL, to get a valid back and forth ID, I would write the following.

JavaScript
JavaScript

I want to get this kind of record retrieval in the way by CodeIgniter3 styles. How can I write it as codeigniter3 active record?

@sajushko

Thanks for the reply. I have confirmed that it works as I intended.

But what I want to know is how to write it in ActiveRecord of CodeIgniter3 instead of SQL statements.

Specifically, it’s something like this.

JavaScript

Since writing SQL statements directly into business logic is a cause of SQL injection, we want to write them using a wrapper function.

Advertisement

Answer

well, I figured out how to write it as codeigniter3 style, like this.

Please let me know any other code more cool than I.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement