Page 310 - Beginning PHP 5.3
P. 310
Part III: Using PHP in Practice
< ?php if ( $start > 0 ) { ? >
< a href=”number_squaring.php?start= < ?php echo $start - PAGE_SIZE
? > ” > < Previous Page < /a > |
< ?php } ? >
< a href=”number_squaring.php?start= < ?php echo $start + PAGE_SIZE ? > ” > Next
Page > < /a >
< /p >
< /body >
< /html >
Figure 10-1
H ow I t W orks
The script starts with the regular XHTML page header, adding some CSS styles for the table in the
page. Next the script defines a constant, PAGE_SIZE , that holds the number of squares to display on
each page (ten in this case).
The script then creates a variable, $start , to hold the first integer to display within the page. This
defaults to zero. However, if the field start has been passed to the script in a query string — and the
field ’ s value is within an acceptable range — this value is used instead. Note that the script casts
the value of $_GET[ “ start “ to an integer as a security measure; it ’ s always good to filter and/or
]
validate any user input to make sure it is of the correct format:
272
9/21/09 9:05:09 AM
c10.indd 272
c10.indd 272 9/21/09 9:05:09 AM