Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
HTML/CSS Responsive question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Skythrust" data-source="post: 467952" data-attributes="member: 87030"><p>Already fixed part 1 by using @media</p><p>[CODE=css]@media screen and (max-width: 1280px) { }[/CODE]</p><p></p><p>Now just only the part if the wrapper is full with boxes to fill a second page</p><p></p><p>Mobile view: [PAGE1]</p><p>BOX1 - BOX2</p><p>BOX3 - BOX4</p><p>BOX5 - BOX6</p><p>BOX7 - BOX8</p><p></p><p>Mobile view: [PAGE2] (after 30 seconds)</p><p>BOX9 - BOX10</p><p>BOX11 - BOX12</p><p>BOX13 - BOX14</p><p>BOX15 - BOX16</p><p>[automerge]1615203325[/automerge]</p><p>I mean like i would like it works as a carrousel</p><p></p><p>Mobile view: [PAGE1/TAB1]</p><p>BOX1 - BOX2</p><p>BOX3 - BOX4</p><p>BOX5 - BOX6</p><p>BOX7 - BOX8</p><p></p><p>Mobile view: [PAGE2/TAB2] (after 30 seconds)</p><p>BOX9 - BOX10</p><p>BOX11 - BOX12</p><p>BOX13 - BOX14</p><p>BOX15 - BOX16</p><p></p><p>But I have no idea how to realize this.</p><p>[automerge]1617112397[/automerge]</p><p>Back again..</p><p></p><p>I have found the function where I am looking for. It calls Pagination.</p><p>There are a couple option like array_slice() which I have found on StackOverflow.</p><p></p><p>I have found this code below, but I have no idea where I can call my array.</p><p></p><p>Array Persons</p><p>[CODE=json]$persons = '[ </p><p> {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},</p><p> {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"},</p><p> {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"},</p><p> {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"},</p><p> {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"},</p><p> {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"},</p><p> {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"},</p><p> {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"}</p><p>]';[/CODE]</p><p></p><p>PHP Code</p><p>[CODE=php]<?php</p><p>$page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1;</p><p>$total = count( $persons ); //total items in array </p><p>$limit = 20; //per page </p><p>$totalPages = ceil( $total/ $limit ); //calculate total pages</p><p>$page = max($page, 1); //get 1 page when $_GET['page'] <= 0</p><p>$page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages</p><p>$offset = ($page - 1) * $limit;</p><p>if( $offset < 0 ) $offset = 0;</p><p></p><p>$yourDataArray = array_slice( $persons, $offset, $limit );</p><p></p><p></p><p>$link = 'index.php?page=%d';</p><p>$pagerContainer = '<div style="width: 300px;">'; </p><p>if( $totalPages != 0 )</p><p>{</p><p> if( $page == 1 )</p><p> {</p><p> $pagerContainer .= '';</p><p> }</p><p> else</p><p> {</p><p> $pagerContainer .= sprintf( '<a href="' . $link . '" style="color: #c00"> &#171; prev page</a>', $page - 1 );</p><p> }</p><p> $pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>';</p><p> if( $page == $totalPages )</p><p> {</p><p> $pagerContainer .= '';</p><p> }</p><p> else</p><p> {</p><p> $pagerContainer .= sprintf( '<a href="' . $link . '" style="color: #c00"> next page &#187; </a>', $page + 1 );</p><p> } </p><p>} </p><p>$pagerContainer .= '</div>';</p><p></p><p>echo $pagerContainer;</p><p>?>[/CODE]</p><p></p><p>Source: <a href="https://stackoverflow.com/questions/26451362/how-to-add-php-pagination-in-arrays/31989815" target="_blank">https://stackoverflow.com/questions/26451362/how-to-add-php-pagination-in-arrays/31989815</a></p></blockquote><p></p>
[QUOTE="Skythrust, post: 467952, member: 87030"] Already fixed part 1 by using @media [CODE=css]@media screen and (max-width: 1280px) { }[/CODE] Now just only the part if the wrapper is full with boxes to fill a second page Mobile view: [PAGE1] BOX1 - BOX2 BOX3 - BOX4 BOX5 - BOX6 BOX7 - BOX8 Mobile view: [PAGE2] (after 30 seconds) BOX9 - BOX10 BOX11 - BOX12 BOX13 - BOX14 BOX15 - BOX16 [automerge]1615203325[/automerge] I mean like i would like it works as a carrousel Mobile view: [PAGE1/TAB1] BOX1 - BOX2 BOX3 - BOX4 BOX5 - BOX6 BOX7 - BOX8 Mobile view: [PAGE2/TAB2] (after 30 seconds) BOX9 - BOX10 BOX11 - BOX12 BOX13 - BOX14 BOX15 - BOX16 But I have no idea how to realize this. [automerge]1617112397[/automerge] Back again.. I have found the function where I am looking for. It calls Pagination. There are a couple option like array_slice() which I have found on StackOverflow. I have found this code below, but I have no idea where I can call my array. Array Persons [CODE=json]$persons = '[ {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"}, {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"}, {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"}, {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"}, {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"}, {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"}, {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"} ]';[/CODE] PHP Code [CODE=php]<?php $page = ! empty( $_GET['page'] ) ? (int) $_GET['page'] : 1; $total = count( $persons ); //total items in array $limit = 20; //per page $totalPages = ceil( $total/ $limit ); //calculate total pages $page = max($page, 1); //get 1 page when $_GET['page'] <= 0 $page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages $offset = ($page - 1) * $limit; if( $offset < 0 ) $offset = 0; $yourDataArray = array_slice( $persons, $offset, $limit ); $link = 'index.php?page=%d'; $pagerContainer = '<div style="width: 300px;">'; if( $totalPages != 0 ) { if( $page == 1 ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( '<a href="' . $link . '" style="color: #c00"> « prev page</a>', $page - 1 ); } $pagerContainer .= ' <span> page <strong>' . $page . '</strong> from ' . $totalPages . '</span>'; if( $page == $totalPages ) { $pagerContainer .= ''; } else { $pagerContainer .= sprintf( '<a href="' . $link . '" style="color: #c00"> next page » </a>', $page + 1 ); } } $pagerContainer .= '</div>'; echo $pagerContainer; ?>[/CODE] Source: [URL]https://stackoverflow.com/questions/26451362/how-to-add-php-pagination-in-arrays/31989815[/URL] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
HTML/CSS Responsive question
Top