I would like to print out records over multiple pages, I found this by ednark, but do not know how to put it in my code, can you help.
Here is ednarks code:
<?php
/**
* This passes three important pieces of information between page calls, the current page we wish to view, the total number of results, and the numberof results displayed on each page
*
* it is up to the recieveing page to determine defualt values for the first call to this function, as well as use this info passed to actually retieve and display each results, this only gives you the menu, but should give each page enough info to determine what to do
**/
function batchDisplayMenu( $link_location, $current_page, $total_batch_size, $batch_step_size, $extra_get_params=array(), $menu_properties=array() )
{
/// display options
$display_all_pages = FALSE;
$page_display_range = 4;
$show_total_pages = TRUE;
$show_ellipses = TRUE;
$show_next = TRUE;
$show_previous = TRUE;
$show_last = TRUE;
$show_first = TRUE;
/// format templates for displaying menu
$total_pages_format_string = "%s results in %s page(s) : ";
$ellipse_format_string = "...";
$no_ellipse_format_string = " ";
$next_format_string = ">>";
$previous_format_string = "<<";
$first_format_string = "first";
$last_format_string = "last";
$current_page_format_string = "<b>%s</b>";
$blank_page_format_string = " ";
$width = 20;
/// this should overwrite any previous variables
extract($menu_properties);
/// display ranges for pages
$total_pages = ceil( $total_batch_size / $batch_step_size );
$page_range_begin = max( ($current_page-$page_display_range), 1 );
$page_range_span = ($page_display_range*2);
$page_range_end = ($page_range_begin+$page_range_span);
/// pass along, via GET, anything in the extra_get_params array, when a user clicks on new page of results to view
$link_format_string = "<a href=\"{$link_location}?current_page=%s&batch_step_size={$batch_step_size}&total_batch_size={$total_batch_size}";
foreach ( $extra_get_params as $item=>$value ) {
$safe_value = str_replace( '%', '%%', urlencode($value) );
$link_format_string .= "&{$item}={$safe_value}";
}
$link_format_string .= "\">%s</a>";
/// show the X out of Y page results
if ( $show_total_pages ) {
$string .= '<center>';
$string .= sprintf($total_pages_format_string,$total_batch_size,$total_pages);
$string .= '</center>';
}
$string .= '<table border="0" class="batch_list"><tr align="center">';
$string .= '<td nowrap="nowrap">';
/// show link to jump to first page
if ( $show_first ) {
if ( $current_page > 1 ) {
$string .= sprintf($link_format_string,1,$first_format_string
) ." ";
} else {
$string .= $first_format_string ." ";
}
}
/// show link to go back one page
if ( $show_previous ) {
if ( $current_page > 1 ) {
$string .= sprintf($link_format_string,max(($current_page-1),1),$previous_format_string) ." ";
} else {
$string .= $previous_format_string ." ";
}
}
/// to ellipse or not ellipse
$string .= ( $show_ellipses and $page_range_begin>1 ) ? sprintf($ellipse_format_string)." " : sprintf($no_ellipse_format_string)." ";
$string .= '</td>';
/// show either all pages on screen at once, or show only X at a time, like google, a batch of batch pages
if ( $display_all_pages ) {
$link_range = range( 1, $total_pages );
} else{
$link_range = range( $page_range_begin, $page_range_end );
}
/// them meat, show a link to each page of items we have
foreach ( $link_range as $index ) {
$string .= '<td width="'.$width.'" nowrap="nowrap">';
if ( $index == $current_page ) {
$string .= sprintf($current_page_format_string,$index) ." ";
} elseif ( $index <= $total_pages ) {
$string .= sprintf($link_format_string,$index,$index) ." ";
} elseif ( $index > $total_pages ) {
$string .= $blank_page_format_string ." ";
}
$string .= '</td>';
}
$string .= '<td nowrap="nowrap">';
$string .= ( $show_ellipses and $page_range_end<$total_pages ) ? $ellipse_format_string ." " : $no_ellipse_format_string ." ";
/// show a link to skip foreward on epage
if ( $show_next ) {
if ( $current_page < $total_pages ) {
$string .= sprintf($link_format_string,min(($current_page+1),
$total_pages),$next_format_string) ." ";
} else {
$string .= $next_format_string ." ";
}
}
/// show a link to the last page
if ( $show_last ) {
if ( $current_page < $total_pages ){
$string .= sprintf($link_format_string,$total_pages,$last_format_string) ." ";
} else {
$string .= $last_format_string ." ";
}
}
$string .= '</td>';
$string .= '</tr></table>';
return $string;
}
?>
And here is my code:
<?php
$From = $_POST['From'];
$To = $_POST['To'];
mysql_connect("");
mysql_select_db("");
$query = "SELECT * FROM KEYCAD WHERE KEYCAD.`PROCESSEDDATE` BETWEEN '$From' AND '$To' AND ACTIVE LIKE 'Y' AND FOLLOWUPCONTACT LIKE 'Y' ORDER BY SANO";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo"<hr>";
echo"<table border='0' cellpadding='0' cellspacing='0' width='650'>";
printf("
<tr>
<td width='200'>
<table border='0' cellpadding='0' cellspacing='0' width='220'>
<tr>
<td colspan='2' width='220'><b>%s</b></td>
</tr>
<tr>
<td width='101'><b>CU</b></td>
<td width='97'>%s</td>
</tr>
<tr>
<td width='101'><b>(H)</b></td>
<td width='97'>%s</td>
</tr>
<tr>
<td width='101'><b>(W)</b></td>
<td width='97'>%s</td>
</tr>
<tr>
<td width='109'><b>Service Date:</b></td>
<td width='109'>%s</td>
</tr>
<tr>
<td width='109'><b>Contact Date:</b></td>
<td width='109'>%s</td>
</tr>
</table>
</td>
<td width='200'>
<table border='0' cellpadding='0' cellspacing='0' width='202'>
<tr>
<td width='200' colspan='2'>
<div align='left'>
<table border='0' cellpadding='0' cellspacing='0' width='200'>
<tr>
<td width='20'>%s</td>
<td width='20'>%s</td>
<td width='20'>%s</td>
<td width='20'>%s</td>
<td width='20'>%s</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td width='200' colspan='2'> </td>
</tr>
<tr>
<td width='200' colspan='2'> </td>
</tr>
<tr>
<td width='26'><b>VIN</b></td>
<td width='172'>%s</td>
</tr>
<tr>
<td width='68'><b>Repair #</b></td>
<td width='132'>%s</td>
</tr>
<tr>
<td width='68'><b>Tech #</b></td>
<td width='132'>%s</td>
</tr>
</table>
</div>
</td>
<td>
<div align='left'>
<table border='0' cellpadding='0' cellspacing='0' width='250' height='104'>
<tr>
<td height='104'>%s</td>
</tr>
</table>
<table border='0' cellpadding='0' cellspacing='0' width='250' height='15'>
<tr>
<td height='15' width='155'><b>Hotspot:</b></td>
<td height='15' width='91'>%s</td>
</tr>
</table>
</div>
</td>
</tr>
</table>\n",
$row["CUSTOMERNAME"],
$row["CUSTNO"],
$row["HOMEPHONE"],
$row["BUSPHONE"],
$row["CLOSEDATE"],
$row["CONTACTDATE"],
$row["Q1"],
$row["Q2"],
$row["Q3"],
$row["Q4"],
$row["Q5"],
$row["VEHID"],
$row["RO"],
$row["TECH"],
$row["COMMENTS"],
$row["FOLLOWUPCONTACT"]
);
}
echo"<table height='50'></table>\n";
?>
Thanks for your help.