note 43929 modified in ref.dbx by tomsommer

From: Date: Fri, 09 Jul 2004 10:37:49 +0000
Subject: note 43929 modified in ref.dbx by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72919@lists.php.net to get a copy of this message
Simple function for returning paged result sets. <?php // use: pagedQuery($link, $sql, $rows_per_page, $current_page) function pagedQuery($link, $sql, $nrows = 10, $page = 1) { $handle = dbx_query($link, $sql, DBX_RESULT_UNBUFFERED); $result = new stdClass; $result->link = $this->link; $result->page = $page; $result->data = array(); $result->info['name'] = array(); $start = ($page - 1) * $nrows; $end = $start + $nrows; $result->rows = 0; while ($row = dbx_fetch_row($handle)) { $result->rows++; if (($result->rows > $start) && ($result->rows <= $end)) { $result->data[] = $row; } } if ($result->data[0]) { $result->cols = count($result->data[0]) / 2; $result->info['name'] = array_slice(array_keys($result->data[0]), $result->cols, $result->cols); $result->lastPage = ceil($result->rows / $nrows); } return $result; } ?> --was-- Simple function for returning paged result sets. <?php // use: pagedQuery($link, $sql, $rows_per_page, $current_page) function pagedQuery($link, $sql, $nrows = 10, $page = 0) { $handle = dbx_query($link, $sql, DBX_RESULT_UNBUFFERED); $result = new stdClass; $result->link = $this->link; $result->page = $page; $result->data = array(); $result->info['name'] = array(); $start = ($page - 1) * $nrows; $end = $start + $nrows; $result->rows = 0; while ($row = dbx_fetch_row($handle)) { $result->rows++; if (($result->rows > $start) && ($result->rows <= $end)) { $result->data[] = $row; } } if ($result->data[0]) { $result->cols = count($result->data[0]) / 2; $result->info['name'] = array_slice(array_keys($result->data[0]), $result->cols, $result->cols); $result->lastPage = ceil($result->rows / $nrows); } return $result; } ?> http://php.net/manual/en/ref.dbx.php

« previous php.notes (#72919) next »