Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking script more dynamic
    primarykey
    data
    text
    <p>I am trying to make my pagination script a bit more dynamic and am needing some help with the calculating of the page numbers part.</p> <p>I have this script below which calculates the number of pages using php, however I would like to add other buttons that when clicked will filter and sort out data which means the pagination numbers need to be calculated again.</p> <p>The script I have does not allow for this to happen, so I am wondering if there is a more efficient/dynamic way of calculating the pagination numbers then the way I am doing it now.</p> <p>This is the main page (pagination.php)</p> <pre><code>&lt;?php include('config.php'); $per_page = 3; //Calculating no of pages $sql = "select * from explore"; $result = mysql_query($sql); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1`` /jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery_pagination.js"&gt;&lt;/script&gt; &lt;div id="loading" &gt;&lt;/div&gt; &lt;div id="content" data-page="1"&gt;&lt;/div&gt; &lt;ul id="pagination"&gt; &lt;?php //Pagination Numbers for($i=1; $i&lt;=$pages; $i++) { echo '&lt;li class="page_numbers" id="'.$i.'"&gt;'.$i.'&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; &lt;br /&gt; &lt;br /&gt; </code></pre> <p>And here is the JS script (jquery.pagination.js)</p> <pre><code>$(document).ready(function(){ //Display Loading Image function Display_Load() { $("#loading").fadeIn(900,0); $("#loading").html("&lt;img src='bigLoader.gif' /&gt;"); } //Hide Loading Image function Hide_Load() { $("#loading").fadeOut('slow'); }; //Default Starting Page Results $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'}); Display_Load(); $("#content").load("pagination_data.php?page=1", Hide_Load()); //Pagination Click $("#pagination li").click(function(){ Display_Load(); //CSS Styles $("#pagination li") .css({'border' : 'solid #dddddd 1px'}) .css({'color' : '#0063DC'}); $(this) .css({'color' : '#FF0084'}) .css({'border' : 'none'}); //Loading Data var pageNum = this.id; $("#content").load("pagination_data.php?page=" + pageNum, function(){ Hide_Load(); $(this).attr('data-page', pageNum); }); }); }); </code></pre> <p>I tried to put the calculation part of the script in 'pagination_data.php' file so when I clicked a button or link to go to that page it would generate everything, but it did not work.</p> <p>So, any help on figuring out a good way of doing this would be great. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload