Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209

    Site crashes on pagination use

    So my issue is that when you go to a page further than about page 6, the site "crashes". Any idea why?


    Code:
    <?php 
        $limit = $settings['pagination']; 
    	$targetpage = "index.php";
    	$add = "";	
    	
    	if(isset($_GET['version'])) $add = "&version=".$_GET['version'];
    	if(isset($_GET['country'])) $add = "&country=".$_GET['country'];
    	if(isset($_GET['category'])) $add = "&category=".$_GET['category'];
    	if(isset($_GET['sort'])) $add = "&sort=".$_GET['sort'];
    	
        $query = "SELECT COUNT(*) as num FROM `servers` WHERE `disabled` = 0 {$offline_where} {$category_filter} {$country_filter} {$version_filter}"; 
        $total_pages = mysql_fetch_array(mysql_query($query)); 
        $total_pages = $total_pages['num']; 
    
    
        $stages = 3; 
    
    
        if (!isset($_GET['page'])) { $_GET['page'] = 0;} else {$page = $_GET['page'];} 
        $page = mysql_real_escape_string($_GET['page']); 
        if($page){ 
            $start = ($page - 1) * $limit; 
        }else{ 
            $start = 0; 
            } 
    
    
        // Get page data 
        $query1 = "SELECT * FROM `servers` LIMIT $limit"; 
        $result = mysql_query($query1); 
    
    
        // Initial page num setup 
        if ($page == 0){$page = 1;} 
        $prev = $page - 1; 
        $next = $page + 1; 
        $lastpage = ceil($total_pages/$limit); 
        $LastPagem1 = $lastpage - 1;         
    
    
    if ($page == '1' && $total_pages <= $settings['pagination'] ){
    
    
    } else {
        echo  "<ul class='pagination'>"; 
        $paginate = ''; 
       // if($lastpage > 1) 
       // {
            // Previous 
            if ($page > 1){ 
                echo  "<li><a href='$targetpage?page=$prev" . $add . "'><</a></li>"; 
            } 
            else{ 
                echo  "<li class='disabled'><a href='#'><</a></li>";    } 
    
    
            // Pages 
            if ($lastpage < 7 + ($stages * 2))    // Not enough pages to breaking it up 
            { 
                for ($counter = 1; $counter <= $lastpage; $counter++) 
                { 
                    if ($counter == $page){ 
                        echo  "<li class='active'><a href='#'>$counter</a></li>"; 
                    }else{ 
                        echo  "<li><a href='$targetpage?page=$counter" . $add . "'>$counter</a></li>";} 
                } 
            } 
            elseif($lastpage > 5 + ($stages * 2))    // Enough pages to hide a few? 
            { 
            // Beginning only hide later pages 
                if($page < 1 + ($stages * 2)) 
                { 
                    for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) 
                    { 
                        if ($counter == $page){ 
                            echo  "<li class='active'><a href='#'>$counter</a></li>"; 
                        }else{ 
                            echo  "<li><a href='$targetpage?page=$counter" . $add . "'>$counter</a></li>";} 
                    } 
                    echo  "<li><a href='#'>...</a></li>"; 
                    echo  "<li><a href='$targetpage?page=$LastPagem1" . $add . "'>$LastPagem1</a></li>"; 
                    echo  "<li><a href='$targetpage?page=$lastpage" . $add . "'>$lastpage</a></li>"; 
                } 
            // Middle hide some front and some back 
                elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) 
                { 
                    echo  "<li><a href='$targetpage?page=1" . $add . "'>1</a></li>"; 
                    echo  "<li><a href='$targetpage?page=2" . $add . "'>2</a></li>"; 
                    echo  "<li><a href='#'>...</a><li>"; 
                    for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) 
                    { 
                        if ($counter == $page){ 
                            echo  "<li class='active'><a href='#'>$counter</a></li>"; 
                        }else{ 
                            echo  "<li><a href='$targetpage?page=$counter" . $add . "'>$counter</a></li>";} 
                    } 
                    echo  "..."; 
                    echo  "<li><a href='$targetpage?page=$LastPagem1" . $add . "'>$LastPagem1</a></li>"; 
                    echo  "<li><a href='$targetpage?page=$lastpage" . $add . "'>$lastpage</a></li>";         
                } 
            // End only hide early pages 
                else 
                { 
                    echo  "<li><a class='button' href='$targetpage?page=1" . $add . "'>1</a></li>"; 
                    echo  "<li><a class='button' href='$targetpage?page=2" . $add . "'>2</a><li>"; 
                    echo  "<li><a href='#'>...</a></li>"; 
                    for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) 
                    { 
                        if ($counter == $page){ 
                            echo  "<li class='active'><a href='#'>$counter</a></li>"; 
                        }else{ 
                            echo  "<li><a href='$targetpage?page=$counter" . $add . "'>$counter</a></li>";} 
                    } 
                } 
            } 
            // Next 
                if ($page < $counter - 1){
                    echo  "<li><a href='$targetpage?page=$next" . $add . "'>></a></li>"; 
                }else{
    				echo  "<li class='disabled'><a href='#'>></a></li>"; 
                } 
    			          //  } 
     // Pagination 
    echo  "</ul>"; 
    }
    ?>

    Each page is querying about 10 servers, and there are 118 servers in the database. Site is senceservers.net if you wish to test this..


    Thanks!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Describe the steps we can take to get it to crash. I don't see any pages that are numbered


  4. #3
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    Quote Originally Posted by mlseim View Post
    Describe the steps we can take to get it to crash. I don't see any pages that are numbered
    His server is timing out.
    Senceservers.net/index.php?=7 will crash it.

    OP I am unable to get to my computer for a few days but I will have a better look once I can get to it. Although I am sure someone else may point out the problem before I can.


    Sent from my iPhone using Tapatalk

  5. #4
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Still having this issue....

  6. #5
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Use print_r() to output all of your variables and see what you get, if anything. Most likely, the script is failing when it tries to output data it doesn't have. Make sure you're testing all of your data before you attempt to use it and provide a failsafe if it isn't returning something usable.


    For instance, say you have a variable that should have an associative array in it with data from the database. You need a failsafe in case the database doesn't return data, otherwise the site will "crash".


    So,
    Code:
    $array = $query_result;
    if($array && count($array) > 0){
      // Do the thing
    } else {
      // $hit went south. Do the backup thing
    }
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:01 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com