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.
I solved the problem.
First, you need the convert each column name in $cols to $table.columnName with php.
And as result query looks like this: