Paginate any query

From: Date: Tue, 17 Feb 2004 21:12:18 +0000
Subject: Paginate any query
Groups: php.general 
Request: Send a blank email to php-general+get-178019@lists.php.net to get a copy of this message
Hi, I use the following function to display any query i send to it. Some of these queries produce 1000's of rows and produce an internal server error, is there a way to paginate any query sent to it - say 1000 rows per page? Thanks for your help // query functions function doQuery($query){ if(!($result = mysql_query(stripslashes($query)))){ echo '<br><br><div align="center">'.mysql_error().'</div>'; exit; } else { $num_fields = mysql_num_fields($result); $num_rows = mysql_num_rows($result); if ($num_fields > 0 && $num_rows > 0){ echo ' <table border="1" cellspacing="0" cellpadding="2" bordercolor="#FFFFFF"> <tr>'; for($i = 0; $i < mysql_num_fields($result); $i++){ echo '<td bgcolor="#ffffff" align="center"><strong>'.mysql_field_name($result, $i).'</strong></td>'; } for($i = 0; $i < mysql_num_rows($result); $i++){ echo '<tr>'; $row_array = mysql_fetch_row($result); for($j = 0; $j < mysql_num_fields($result); $j++){ echo '<td bgcolor="#eeeeee" align="center">'.$row_array[$j].'</td>'; } echo '</tr>'; } echo '</table>'; } else { echo '<br><br><div align="center">No data in table</div>'; } } }

« previous php.general (#178019) next »