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

  • Home
  • SEARCH
  • 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 6061437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:56:16+00:00 2026-05-23T08:56:16+00:00

I am asked to fix a php function in my work. The prototype is:

  • 0

I am asked to fix a php function in my work. The prototype is:

function select($cols, $table, $cond, $order, $start, $max);

It queries the database with odbc_exec() and returns the number of rows with odbc_num_rows(). Function code is like this:

$this->query = "SELECT $cols FROM $table ";
if($cond) $this->query .= "WHERE $cond";
if($order) $this->query .= " ORDER BY ".$order;

This function is used in many places so i can’t write it from scratch. It gets records from many tables. Until yesterday it was not using $max variable so it was reading all the records from the database. They are using iSeries Access ODBC Driver. I looked at here for answer but couldn’t found.

I want to use the $start variable, to start reading from $start and read $max rows. If $start is 100 and $max 50, i want to get the records between 100-150. I added this part yesterday:

if($max) $this->query .= " FETCH FIRST " . $max . " ROWS ONLY ";

I couldn’t found anything useful for my problem. I know i can do it for one table using id or something like that. But i am looking for a general solution.

  • 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-23T08:56:17+00:00Added an answer on May 23, 2026 at 8:56 am

    I solved the problem.

    First, you need the convert each column name in $cols to $table.columnName with php.

    $this->query .= " ( SELECT ROW_NUMBER() OVER() AS rownum, $convertedColumns
                           FROM $table ) AS tmp WHERE rownum > ". $start ." " ;
    if($max) {
        $last = $start + $max;
        $this->query .= " AND rownum <= ". $last . " ";
    }
    

    And as result query looks like this:

    SELECT $cols FROM 
        ( SELECT ROW_NUMBER() OVER() AS rownum, $convertedCols ) AS tmp
    WHERE rownum > $start AND rownum <= $max
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I once was asked to increase thread priority to fix a problem. I refused,
A client has just asked me to fix an issue with their webside. I
I've asked this question before, here , however that solution didn't fix it when
I've been reading a lot about this since I've been asked to fix a
So I attempted to build what I asked about in this question: Fix voting
When asked to create system XYZ and you ask to do it in Python
I asked a couple of coworkers about AnkhSVN and neither one of them was
(I asked this question in another way , and got some interesting responses but
I asked a somewhat related question but I want it to make it more
I asked here about a protocol that I was asked to implement, and how

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.