Jump to content

Search the Community

Showing results for tags 'pagination'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 9 results

  1. Hello. I have a page that displays data from a database based on pagination. All works well if I display all records (19 at the moment), but if I choose to view 8, or 10, or less than 19, I see duplicates of the same data, as well as new data not showing. How can I prevent duplications and have new date viewed without having to view all data? include("headsection.php"); include("nav.php"); if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $num_per_page = 20; $start_from = ($page -1) * 2; $sql = "SELECT * FROM people ORDER BY id ASC LIMIT $start_from, $num_per_page"; $result = $con->query($sql); if( $result->num_rows > 0) { ?> <h1 class="center">List of all Users</h1> <table class="container3"> <tr> <td width="auto">PID</td> <td width="auto">Name</td> <td width="auto">Relationship</td> <td width="auto" class="center" colspan="3">Actions</td> </tr> <form action="" method="POST"> <?php while( $row = $result->fetch_assoc()){ echo "<input type='hidden' value='". $row['id']."' name='id'>"; //added echo "<tr>"; echo "<td class='success'>".$row['pid'] . "</td>"; echo "<td class='success'>".$row['name'] . "</td>"; echo "<td class='success'>".$row['relationship'] . "</td>"; echo "<td><a href='view.php?id=".$row['id']."' class='primary' title='view'>V</a></td>"; echo "<td><a href='edit.php?id=".$row['id']."' class='warning' title='edit'>E</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."' class='danger' title='delete'>D</a></td>"; echo "</tr>"; } ?> </form> </table> <?php $pr_query = "SELECT * FROM people ORDER BY id"; $pr_result = $con->query($pr_query); $total_record = mysqli_num_rows($pr_result); //echo $total_record; $total_page = ceil($total_record/$num_per_page); echo "<h3 class='center'>Number of records in database: " . $total_record . "</h3>"; echo "<p class='center'>"; if ($page > 1 ){ echo "<a class='primary' href='users.php?page=".($page-1)."'>Previous</a>"; } for($i=1; $i<$total_page; $i++) { echo "<a class='primary' href='users.php?page=".$i."'>$i</a>"; } if ($i > $page ){ echo "<a class='primary' href='users.php?page=".($page+1)."'>Next</a>"; } echo "</p>"; ?> <br><br> <?php } else { echo "<br><br>No Record Found"; } ?> <?php include("footsection.php"); ?> As the site is localhosted, i am using mysqli - the site will not be online. Thanks in advance for any help.
  2. Hi folks, brand new here and hope that you can help me; I'm looking for very generic pagination for my page. I'll paste in some html and go from there: <div class="row paginate"> <div class="col-12"> <nav> <a href="index.php" class="active">01</a> <a href="index-02.php">02</a> <a href="index-03.php">03</a> <a href="index-04.php">04</a> <a href="index-05.php">05</a> </nav> </div> </div> What I'm looking for is php inside of the link to echo the .active class based on whether or not you're on the index-02.php page or index-03.php page etc... I'm not using any mysql for this so I hope it's possible. I also plan on putting that chunk of html in an include file so I don't have to manually keep adding new links to every page :/ The site it's going on is one of my own at http://www.harshclimate.com/photos if you wanna see the entire HTML Thanks, all!
  3. Hi I'm trying to make a "pagination" for my webpage so people can flick through several pages of images (6 columns by 4 rows). The code is meant to check how many pages are needed and display a maximum of 5 page links, 2 links for the pages before the current page and 2 links for the pages just after. Anyway, I have tested it and the if statements are only read when the for loop is removed however the latter is necessary for this code to work. Also I'm very basic in my coding as I'm still new. here is my code: if ($numberofobjects > '23') { function getCurrentPageUrl() { $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $hrefpages = getCurrentPageUrl(); $draftnumberofpages = $numberofobjects / '24'; $numberofpages = count($draftnumberofpages, 0, PHP_ROUND_HALF_UP); $currentpage = substr($hrefpages, -1); $linkwithoutpage = substr($hrefpages, 0, -1); $prevpage1 = $currentpage - '1'; $nextpage1 = $currentpage + '1'; $prevpage2 = $currentpage - 2; $nextpage2 = $currentpage + 2; $keepgoing = '0'; $currentpagination = '0'; $nomoreprev = '0'; $nomorenext = '0'; echo '<div class="row"></div>'; echo '<div class="row"></div>'; echo '<div class="pagination-centered"> <ul class="pagination">'; if ($currentpage != '1') { echo '<li class="arrow"><a href="'.$linkwithoutpage.$prevpage1.'">«</a></li>'; } for ($paginationincrement = 0; $paginationincrement == 5; $keepgoing++) { if ($prevpage2 >= 1) { echo '<li ><a href="'.$linkwithoutpage.$prevpage2.'">'.$prevpage2.'</a></li>'; echo '<li ><a href="'.$linkwithoutpage.$prevpage1.'">'.$prevpage1.'</a></li>'; $paginationincrement + 2; $nomoreprev = '1'; } if ($prevpage1 >= 1 && $nomoreprev != 1 ) { echo '<li ><a href="'.$linkwithoutpage.$prevpage1.'">2</a></li>'; $paginationincrement ++; } if ($currentpagination == '0') { $paginationarray = '<li class="current"><a href="#">'.$currentpage.'</a></li>'; $paginationincrement++; $currentpagination = '1'; } if ($nextpage2 <= $numberofpages) { echo '<li ><a href="'.$linkwithoutpage.$nextpage2.'">'.$nextpage1.'</a></li>'; echo '<li ><a href="'.$linkwithoutpage.$nextpage1.'">'.$nextpage2.'</a></li>'; $paginationincrement + 2; $nomorenext = 1; } if ($nextpage1 <= $numberofpages && $nomorenext != 1) { echo '<li ><a href="'.$linkwithoutpage.$nextpage1.'">'.$nextpage1.'</a></li>'; $paginationincrement ++; } if ($paginationincrement == $numberofpages) { $paginationincrement = 5; } } if ($currentpage != $numberofpages) { echo '<li class="arrow"><a href="'.$linkwithoutpage.$prevpage1.'">»</a></li>'; } echo ' </ul> </div></div>'; }
  4. Hi, I'm having a real problem with one of my Wordpress category pages. I use a 3-column grid system on this page and just recently I needed to add an advert to the page, so I thought I would do one query at the top with the first two posts, then add the advert to complete the row. Then I would use a second query underneath creating the posts using the traditional grid system with 3 in each row. This is working well except for the pagination, which adds the two items form the first query everytime it paginates. You can see this in action at http://soundsandcolours.com/music/ Does anyone know what I can do to make the Pagination ignore the first query, and just keep running the second query instead. I've included all of my code below: 1st Query: $query_string; $musiccat_posts = new WP_Query($query_string."&posts_per_page=2"); if ($musiccat_posts->have_posts()): $musiccatIDs = array(); while($musiccat_posts->have_posts()):$musiccat_posts->the_post(); $musiccatIDs[] = get_the_ID(); 2nd Query: $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; global $moremusiccat_query; $music_args = array( 'cat' => 1841, 'posts_per_page' => 15, 'post__not_in' => $musiccatIDs, 'paged' => $paged ); $moremusiccat_query = new WP_Query( $music_args ); while ($moremusiccat_query -> have_posts()) : $moremusiccat_query -> the_post(); ?> Pagination Code: $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $moremusiccat_query->max_num_pages ) ); Any help would be massively appreciated!
  5. Have basic article directory and i'm busy with pagination. And i want to have it shortlinked. Structure of the link looks like this: Without pagination <a href='moving-articles/category/$sublink/'>$sublink</a> rewrite rule in .htaccess look like this RewriteRule moving-articles/(.*)/(.*)/$ /moving-articles.php?$1=$2 That works perfectly fine. So the problem i have here, one i try to add pagination. Link structure is like this for example: <a href='moving-articles/category/$sublink/page/2/'>2</a> rewrite rule in .htaccess: RewriteRule moving-articles/(.*)/(.*)/(.*)/(.*)/$ /moving-articles.php?$1=$2&$3=$4 And piece of php code responsible for calling variables: if(isset($_GET['category']) && isset($_GET['page'])) { $sublink=$_GET['category']; $page=$_GET['page']; ..... } What do i do wrong here? Thanks for your help in advance!
  6. Hi, I got a problem with pagination. I got a script but the problem is that I use the connection to database with "mysqli" NOT "mysql". Im newbe with mysqli and I dont know how can I change the pagination script to work. <?php $dbConnect= mysqli_connect('localhost', 'user', 'password') or die('Cant connect'); mysqli_select_db($dbConnect, 'database') or die('Cant connect to database'); mysqli_set_charset($dbConnect, "utf8"); ?> And this is a script for pagination <?php $limit = 4; $sql = "select count(c_vesti_id) from c_vesti"; $c = array_shift(mysql_fetch_row(mysql_query($sql))); $maxpage = ceil($c / $limit); $page = isset($_GET['page']) ? abs((int)$_GET['page']) : 1; if ($page <= 0) { $page = 1; } else if ($page >= $maxpage) { $page = $maxpage; } $offset = ($page-1) * $limit; $query = mysql_query("select * from c_vesti limit $offset, $limit "); while ($row = mysql_fetch_assoc($query)) { print $row['c_vesti_naslov']."<br />"; } // $linklimit = 4; $linklimit2 = $linklimit / 2; $linkoffset = ($page > $linklimit2) ? $page - $linklimit / 2 : 0; $linkend = $linkoffset+$linklimit; if ($maxpage - $linklimit2 < $page) { $linkoffset = $maxpage - $linklimit; if ($linkoffset < 0) { $linkoffset = 0; } $linkend = $maxpage; } if ($page > 1) { print "<a href='?page=".($page-1)."'>Back</a> "; } for ($i=1+$linkoffset; $i <= $linkend and $i <= $maxpage; $i++) { $style = ($i == $page) ? "color: black;" : "color: blue;"; print "<a href='?page=$i' style='$style'>[$i]</a> "; } if ($page < $maxpage) { print "<a href='?page=".($page+1)."'>Forward</a>"; } ?> Thanks in advanced for help T
  7. Hello, I have problem with my pagination script, I tried to add tags to it but selecting second page (next page) when tag is working and filter content of the page, gets me back to second page with content without tag. It should look like this: gallery/page/2/?s=&tag=2 instead: gallery/page/2 I just dont know what to do. Can you help me out? My pagination script: <?php foreach ($this->pagesInRange as $page): ?> <?php if ($page != $this->current): ?> <li><a href="<?php echo $this->url($this->route, array('page' => $page ), true); ?>"><?php echo $page; ?></a></li> <?php else: ?> <li class="active"><a href="#"><?php echo $page; ?></a></li> <?php endif; ?> <?php endforeach; ?>
  8. Hi Im new here.. Im a PHP noo-b i have this simple code with sorting and pagination with dummy data (firstname,lastname,age) I would like to add some simple search to it..im not sure if im doing this right currentlty the search is not working properly for testing purpose, right now i limit 3 records per page a. when i search record and search result is display..Pagination link is still display even i have only 1record search result b. if i have 4 records found, when i click the 2nd page, the search result is gone and table is back to default view c. in table default view, clicking 2nd page and try to search record, records are not found because its looking under the 2nd page and not all of the table sorry for my English <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Paging</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <form method="post" action="" > <br />Search <input type="text" name="search" /> <input type="submit" value="Search"/></form><br /> <?php require "connect.php"; // All database details will be included here // define values the rest of the code uses $table = 'person'; // database table name $sorts = array('firstname'=>'First Name','lastname'=>'Last Name','age'=>'Age'); // list of permissible sort choices $sort_bys = array('asc','desc'); // list of permissible order by choices $limit = 3; // No of records to be shown per page. // condition inputs/set default values $start = (isset($_GET['start'])) ? (int)$_GET['start'] : 0; // default to starting row 0 if not specified $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'firstname'; // default to firstname if not specified $sort_by = (isset($_GET['sort_by'])) ? $_GET['sort_by'] : 'asc'; // default to asc if not specified // validate sort input (used as a keyword in query statement) if(!array_key_exists($sort,$sorts)){ $sort = 'firstname'; // default to firstname } // validate sort_by input (used as a keyword in query statement) if(!in_array($sort_by,$sort_bys)){ $sort_by = 'asc'; // default to asc } $eu = $start; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; // get opposite sort_by value for producing toggle links in the table heading (only) if($sort_by == 'asc'){ $sort_order = 'desc'; } else { $sort_order = 'asc'; } /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query="SELECT COUNT(*) FROM $table"; $result=mysql_query($query); //echo $query, mysql_error(); list($nume) = mysql_fetch_row($result); /////// The variable nume above will store the total number of records in the table//// /////////// Now let us print the table headers //////////////// $bgcolor="#f1f1f1"; echo "<table border='1'>" ; echo "<tr> <th>ID</th>"; // dynamically produce choices/columns foreach($sorts as $key=>$value){ echo "<th><a href='?sort=$key&sort_by=$sort_order'>$value</a></th>"; } echo "</tr>"; ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// //$query="SELECT * FROM $table ORDER BY $sort $sort_by limit $eu, $limit"; $query="SELECT * FROM $table where firstname like '%" . $_POST['search'] . "%' or lastname like '%" . $_POST['search'] . "%' or age like '%" . $_POST['search'] . "%' ORDER BY $sort $sort_by limit $eu, $limit"; $result=mysql_query($query); //echo $query, mysql_error(); $count = (isset($eu) && $eu > 0) ? $eu+1 : 1; //////////////// Now we will display the returned records in side the rows of the table///////// while($rows = mysql_fetch_array($result)){ // toggle bgcolor if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';} else{$bgcolor='#f1f1f1';} echo "<tr >"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>"; echo $count++; echo "</font></td>"; echo "<td>$rows[firstname]</td>"; echo "<td>$rows[lastname]</td>"; echo "<td>$rows[age]</td>"; echo "</tr>"; } echo "</table>"; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////////////////////// if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging /////////////// Start the bottom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0){ $_GET['start'] = $back; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); print "<a href='?$q'><font face='Verdana' size='2'>PREV</font></a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ $_GET['start'] = $i; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); echo " <a href='?$q'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume){ $_GET['start'] = $next; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); print "<a href='?$q'><font face='Verdana' size='2'>NEXT</font></a>"; } echo "</td></tr></table>"; }// end of if checking sufficient records are there to display bottom navigational link. include "menu.php"; ?>
  9. Hi friends, i have a problem. i try to make pagination. I didn't added numbers and the number stayed next to the images. Numbers is no display and it is next the images. And i don't want to give "padding-left" for first image but when i use "padding-left" for images, it is giving all of them. <?php $sayfa = intval($_GET["sayfa"]); if(!$sayfa) {$sayfa = 1;} $say = $db->query("SELECT * FROM resimlerekle"); $toplamveri = $say->rowCount(); // Verileri Saydırdık $limit = 8; $sayfa_sayisi = ceil($toplamveri/$limit); if($sayfa > $sayfa_sayisi) { $sayfa = 1; } $goster = $sayfa * $limit - $limit; $gorunensayfa = 6; $resimcek = $db->query("SELECT * FROM resimlerekle ORDER BY cokluresimekle_id DESC LIMIT $goster,$limit"); $resimlerial = $resimcek->fetchAll(PDO::FETCH_ASSOC); ?> <?php foreach ($resimlerial as $resim) { ?> <div style="float: left; padding-left: 10px;"> <div><img <?php echo $resim; ?> style="max-width:250px;" src="../../../upload/cokluresim/<?php echo $resim["cokluresimekle_resim"]; ?>" ></div> <div style="max-width:250px; max-height:50px; background-color:#d6d4d4; line-height:50px; text-align:center;"><?php echo $resim['cokluresimekle_baslik']; ?></div> </div> <?php } ?> <!-- Benim Eklediğim Kodlar Bitiş --> <?php if ($sayfa > 1) { ?> <span><a href="index.php?sayfa=1">İlk</a></span> <div><a href="index.php?sayfa=<?php echo $sayfa - 1 ?>">Önceki</a></div> <?php } ?> <?php for($i = $sayfa - $gorunensayfa; $i < $sayfa + $gorunensayfa +1; $i++) { if($i > 0 and $i <= $sayfa_sayisi) { if($i == $sayfa) { echo '<span>'.$i.'</span>'; }else{ echo '<a href="index.php?sayfa='.$i.'">'.$i.'</a>'; } } } ?> <?php if ($sayfa != $sayfa_sayisi) { ?> <div><a href="index.php?sayfa=<?php echo $sayfa + 1 ?>">Sonraki</a></div> <div><a href="index.php?sayfa<?php echo $sayfa_sayisi ?>">Son</a></div> <?php } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.