User's Manual
Navigating Through Database Records
Beta Draft Querying Data 4-7
Q Detecting if the HTTP request for the page was posted by clicking the next or
previous button.
Q Tracking the last row queried by using HTTP session state. A PHP session is
started to maintain state information for a specific client between HTTP requests.
The first HTTP request will retrieve the first data row and initialize the session
state. A subsequent request initiated with navigation buttons combined with the
session state from a previous HTTP request enables the application to set variables
that control the next record retrieved by the query.
Q Writing a query that returns a sub set of rows based on a set of conditions whose
values are determined by the application state.
To add navigation through database rows, perform the following steps:
1. Edit anyco_ui.inc. Add Next and Previous navigation buttons to the
departments Web page. Change the ui_print_departments() function to
append a second parameter called $posturl that supplies the value for the form
attribute action. After printing the </table> tag include HTML form tags for
the Next and Previous buttons:
<?php // File: anyco_ui.inc
...
function ui_print_department($dept, $posturl)
{
...
echo <<<END
</tr>
</table>
<form method="post" action="$posturl">
<input type="submit" value="< Previous" name="prevdept">
<input type="submit" value="Next >" name="nextdept">
</form>
END;
}
}
?>
2. Edit anyco.php. To detect if the Next or Previous button was used to invoke the
page and track session state, call the PHP function session_start(), and create
a function named construct_departments():
Move and modify the database access logic into a new
construct_departments() function, which detects if navigation has been
performed, manages session state, defines a sub query for the database access
layer to process, connects and calls a function db_get_page_data(). The file
becomes:
<php // File: anyco.php
require('anyco_cn.inc');
require('anyco_db.inc');
require('anyco_ui.inc');
session_start();
construct_departments();
function construct_departments()
{
if (isset($_SESSION['currentdept']) &&