Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Bootstrap 4 Pagination Function Replacem
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / M-BiTsy / M-BiTsy Support

2020-03-05 17:11:04
This is a function replacement im  working on to navigate pages better using bootstrap here is the function and example to see.
Im using this for pagination and i just need a table function now and thought id post it if its any use to anyone

This is memberlist.php for testing purposes ($statement = "`[color=rgb(250, 197, 28)]users[/color]` ORDER BY `[color=rgb(250, 197, 28)]id[/color]` ASC"; // Change `[color=rgb(250, 197, 28)]users[/color]` & '[color=rgb(250, 197, 28)]id[/color]' according to your table name.
<?php
require_once("backend/init.php");
dbconn();
loggedinonly();

stdhead(T_("USERS"));
begin_frame(T_("USERS"));

$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]);
if ($page <= 0) $page = 1;

$per_page = 5; // Set how many records do you want to display per page.
$startpoint = ($page * $per_page) - $per_page;
$statement = "`users` ORDER BY `id` ASC"; // Change `users` & 'id' according to your table name.
$results = DB::run("SELECT * FROM {$statement} LIMIT {$startpoint} , {$per_page}");

if ($results->rowCount()) {

   // displaying records this is where main code goes
   while ($row = $results->fetch(PDO::FETCH_LAZY)) {
             echo $row["username"]."<br>";  // if you change query remember change column name
   }

} else {
    echo "No records are found.";
}

// displaying paginaiton.
echo pagination($statement,$per_page,$page,$url='?');

end_frame();
stdfoot();


Add to functions before ?> at end

<?php
function pagination($query,$per_page=10,$page=1,$url='?'){  

   $query = "SELECT COUNT(*) as `num` FROM {$query}";
   $row = DB::run($query)->fetch();
   $total = $row['num'];
   $adjacents = "2";
   
   $prevlabel = "Prev";
   $nextlabel = "Next";
   $lastlabel = "Last";
   
   $page = ($page == 0 ? 1 : $page);
   $start = ($page - 1) * $per_page;                              
   
   $prev = $page - 1;                        
   $next = $page + 1;
   
   $lastpage = ceil($total/$per_page);
   
   $lpm1 = $lastpage - 1; // //last page minus 1
   
   $pagination = "";
   if($lastpage > 1){  
       $pagination .= "<nav aria-label='Page navigation example'><ul class='pagination'>";
  //     $pagination .= "<li class='page-item'><a class='page-link' href='#'>{$page}</a></li>";
                     
           if ($page > 1) $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$prev}'>{$prevlabel}</a></li>";
           
       if ($lastpage < 7 + ($adjacents * 2)){  
           for ($counter = 1; $counter <= $lastpage; $counter++){
               if ($counter == $page)
                   $pagination.= "<li class='page-item'><a class='page-link' >{$counter}</a></li>";
               else
                   $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$counter}'>{$counter}</a></li>";                  
           }
       
       }
     
       elseif($lastpage > 5 + ($adjacents * 2)){
           
           if($page < 1 + ($adjacents * 2)) {
               
               for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
                   if ($counter == $page)
                       $pagination.= "<li class='page-item'><a class='page-link'>{$counter}</a></li>";
                   else
                       $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$counter}'>{$counter}</a></li>";                  
               }
               $pagination.= "<li class='page-link'>...</li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$lpm1}'>{$lpm1}</a></li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$lastpage}'>{$lastpage}</a></li>";
                   
           } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
               
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page=1'>1</a></li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page=2'>2</a></li>";
               $pagination.= "<li class='page-link'>...</li>";
               for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
                   if ($counter == $page)
                       $pagination.= "<li class='page-item'><a class='page-link>{$counter}</a></li>";
                   else
                       $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$counter}'>{$counter}</a></li>";                  
               }
               $pagination.= "<li class='page-link'>..</li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$lpm1}'>{$lpm1}</a></li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$lastpage}'>{$lastpage}</a></li>";    
               
           } else {
               
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page=1'>1</a></li>";
               $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page=2'>2</a></li>";
               $pagination.= "<li class='page-link'>..</li>";
               for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
                   if ($counter == $page)
                       $pagination.= "<li class='page-item'><a class='page-link'>{$counter}</a></li>";
                   else
                       $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$counter}'>{$counter}</a></li>";                  
               }
           }
       }
     
           if ($page < $counter - 1) {
       $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page={$next}'>{$nextlabel}</a></li>";
       $pagination.= "<li class='page-item'><a class='page-link' href='{$url}page=$lastpage'>{$lastlabel}</a></li>";
       }
       
       $pagination.= "</ul></nav>";      
   }
   
   return $pagination;
}



Remember you need bootstrap
    <!-- Required meta tags -->
   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <!-- Bootstrap CSS -->
   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
       integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
   <!-- Optional JavaScript -->
   <!-- jQuery first, then Popper.js, then Bootstrap JS -->
   <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
       integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
   </script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
       integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
   </script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
       integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
   </script>


heres with limit set to 1 for more pages
2020-03-05 21:20:06
Now my table head looks like this

print("<div class='table-responsive'><table class='table table-striped'>
<thead><tr>
<th>" . T_("USERNAME") . "</th>
<th>" . T_("REGISTERED") . "</th>
<th>" . T_("LAST_ACCESS") . "</th>
<th>" . T_("CLASS") . "</th>
<th>" . T_("COUNTRY") . "</th>
</tr></thead>");


and the info, although this is a messy example
print("<tbody><tr>
<td><a href='account-details.php?id=$row[id]'><b>".class_user($row['username'])."</b></a>" .($row["donated"] > 0 ? "<img src='$site_config[SITEURL]/images/star.png' border='0' alt='Donated' />" : "")."</td>"."
<td>".utc_to_tz($row["added"])."</td>
<td>".utc_to_tz($row["last_access"])."</td>
<td>".T_($row["level"])."</td>$country
</tr></tbody></table></div>");


Some css for header
.table thead th {
       color: #fff;
       background-color: #072F5F;
       background-image: -webkit-linear-gradient(top, #072F5F, #3895D3);
       background-image: linear-gradient(to bottom, #072F5F, #3895D3);
       background-repeat: repeat-x;
}
.table tbody td {
   background-color: #EEEEEE;
}


Unknown User
2020-03-06 14:19:12
[USER=20288]@m-jay[/USER] here's a bit of improvement of url part


   // is there already an "?" in query string you have into the url.
   if (strpos($url, '?'))
   {
       $url .= '&';
   }
   else
   {
       $url .= '?';
   }
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 5
  • Members: 0
  • Guests online: 5
  • Comments: 3
  • Messages: 1,728