netfrugal Posted September 29, 2006 Share Posted September 29, 2006 I have thousands of internet log records to review, and before I added pagination to the query , the pages would be miles long, and obviously take a while to load.Now, the pagination makes it look nicer, but it stalls and fails to load after a few seconds.Is there a way to stop the freezing? Or am I out of luck?Below is the code I use. The Red is the actual pagination code, while the rest is the query result.Any help would be appreciated.[B][SIZE=1][COLOR=DarkRed]if(!isset($_GET['page'])){ // If current page number, use it $page = 1;} else { // if not, set one! $page = $_GET['page'];}$max_results = 15; // Define the number of results per page$from = (($page * $max_results) - $max_results); // Figure out the limit for the query based on the current page number. [/COLOR] [/SIZE][/B] if (!$subsearch) { $sql = "SELECT datetime, ident, ip, what, url FROM log WHERE ident = '$username' and datetime between '$begindate 00:00:00' and '$enddate 23:59:59' order by datetime $ordervar [B][SIZE=1][COLOR=DarkRed]LIMIT $from, $max_results[/COLOR] [/SIZE][/B]"; } else { $sql = "SELECT datetime, ident, ip, what, url FROM log WHERE ident = '$username' and url LIKE '%$subsearch%' and datetime between '$begindate 00:00:00' and '$enddate 23:59:59' order by datetime $ordervar [B][SIZE=1][COLOR=DarkRed]LIMIT $from, $max_results[/COLOR] [/SIZE][/B] "; } $result = mysql_query($sql, $connection); print "<table border='2' width='100%' cellspacing='0' cellpadding='0'>\n"; print "<tr><td><font color='#336699'><b>Date Time</b></font></td><td><font color='#336699'><b>Username</b></font></td><td><font color='#336699'><b>Computer Used</b></font></td><td><font color='#336699'><b>Displayed</b></font></td><td><font color='#336699'><b>Web Page Viewed (limit 45 characters)</b></font></td><tr>\n"; while($row= mysql_fetch_array($result)) { $url = substr($row[url], 0, 45); // limit the url string to 45 characters print "<td>$row[datetime]</td><td>$row[ident]</td><td>$row[ip]</td>\n"; if (strstr($row[what], "DENIED")) { print "<td><font color='red'><b>DENIED</b></font></td>\n"; } else { print "<td><font color='green'><b>ALLOWED</b></font></td>\n"; } print "<td><a href='$row[url]' target='_blank'>$url</a></td></tr>\n"; } print "</table>\n"; [B][SIZE=1][COLOR=DarkRed]$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM log"),0); // Figure out the total number of results in DB:$total_pages = ceil($total_results / $max_results); // Figure out the total number of pages. Always round up using ceil()echo "<br><br><center><span class='FormValueBold'>Select a Page</span><br />"; // Build Page Number Hyperlinks// Build Previous Linkif($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "<span class='SmallHeader'>$i</span> "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }}// Build Next Linkif($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";}echo "</center>";[/COLOR][/SIZE][/B] mysql_close($connection); } } Quote Link to comment Share on other sites More sharing options...
sasa Posted September 29, 2006 Share Posted September 29, 2006 try to echo $sql before querywhat is say Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.