Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Design PHP – Display divs inside echo function

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #256374
    Johnboyo
    Participant

    I want to get the article-loop divs to populate inside the echo function in the while loop. I’m trying to create a dynamic pagination that prints the article-loop divs dynamically per page. This is pretty straightforward so for example, when the user changes the page, I want the next few divs to display on that page and so on. It should display 3 divs per page.

    current_page = (int)$page;
        $this->per_page = (int)$per_page;
        $this->total_count = (int)$total_count;
    }
    
    public function offset() {
        return ($this->current_page - 1) * $this->per_page;
    }
    
    public function total_pages() {
        return ceil($this->total_count/$this->per_page);
    }
    
    public function previous_page() {
        return $this->current_page - 1;
    } 
    
    public function next_page() {
        return $this->current_page + 1;
    }
    
    public function has_previous_page() {
        return $this->previous_page() >= 1 ? true : false;
    }
    
    public function has_next_page() {
        return $this->next_page() total_pages() ? true : false;
    }
    }
    
    $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
    $per_page = 2;
    $total_count = 10;
    $pagination = new Pagination($page, $per_page, $total_count);
    ?>
    
    <div class="article-loop">
    <img src="http://i.imgur.com/CmU3tnl.jpg">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/TDdxS9H.png">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/39rpmwB.jpg">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/1lBZQ1B.png">
    </div>
    <div class="article-loop">
    <img src="https://i.imgur.com/Y5Ld4Qfh.jpg">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/8HumESY.jpg">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/CqCZBvk.png">
    </div>
    <div class="article-loop">
    <img src="http://i.imgur.com/wQVPRVp.png">
    </div>
    <div>
        offset() + 1;
            $limit = $pagination->per_page;
            while($itotal_count && $limit>0) {
                echo '**IN HERE POPULATE THE ARTICLE-LOOP DIVS**';
                $i++;
                $limit--;
            }
        ?>
    </div>
    <ul>
        has_previous_page()) {
                echo '<li><a>previous_page().'">«</a></li>';
            } else {
                echo '<li class="disabled"><a href="#">«</a></li>';
            }
        ?>
        <?php
            for($i=1; $itotal_pages(); $i++) {
                echo '<a href="index.php?page='.$i.'"><li style="margin-left:5px;margin-right:5px">'.$i.'</li></a>';
            }
        ?>
        has_next_page()) {
                echo '<li><a>next_page().'">»</a></li>';
            } else {
                echo '<li class="disabled"><a href="#">»</a></li>';
            }
        ?>
    </ul>
    
Viewing 1 post (of 1 total)
  • The forum ‘Design’ is closed to new topics and replies.