php - How to create a "Next Page" link to the "non-displayed" results of mySQL search? -


i have search engine on webpage (php). far, show results on same result page. want limit number of results 20 per page, , create "next page" link...

if select top 20 * ... ... show top 20 results...

how create <a href="...">nextpage</a> lead results 21 40? have use ajax?

<?php<br> // database connection info<br> $conn = mysql_connect('localhost','dbusername','dbpass') or trigger_error("sql", e_user_error);<br> $db = mysql_select_db('dbname',$conn) or trigger_error("sql", e_user_error);<br>  // find out how many rows in table <br> $sql = "select count(*) numbers";<br> $result = mysql_query($sql, $conn) or trigger_error("sql", e_user_error);<br> $r = mysql_fetch_row($result);<br> $numrows = $r[0];<br>  // number of rows show per page<br> $rowsperpage = 10;<br> // find out total pages $totalpages = ceil($numrows / $rowsperpage);<br>  // current page or set default<br> if (isset($_get['currentpage']) && is_numeric($_get['currentpage'])) {<br>    // cast var int<br>    $currentpage = (int) $_get['currentpage'];<br> } else {<br>    // default page num<br>    $currentpage = 1;<br> } // end if<br>  // if current page greater total pages...<br> if ($currentpage > $totalpages) {<br>    // set current page last page<br>    $currentpage = $totalpages;<br> } // end if<br> // if current page less first page...<br> if ($currentpage < 1) {<br>    // set current page first page<br>    $currentpage = 1;<br> } // end if<br>  // offset of list, based on current page <br> $offset = ($currentpage - 1) * $rowsperpage;<br>  // info db <br> $sql = "select id, number numbers limit $offset, $rowsperpage";<br> $result = mysql_query($sql, $conn) or trigger_error("sql", e_user_error);<br>  // while there rows fetched...<br> while ($list = mysql_fetch_assoc($result)) {<br>    // echo data<br>    echo $list['id'] . " : " . $list['number'] . "<br />";<br> } // end while  /******  build pagination links ******/<br> // range of num links show<br> $range = 3;<br>  // if not on page 1, don't show links<br> if ($currentpage > 1) {<br>    // show << link go page 1<br>    echo " <a href='{$_server['php_self']}?currentpage=1'><<</a> ";<br>    // previous page num<br>    $prevpage = $currentpage - 1;<br>    // show < link go 1 page<br>    echo " <a href='{$_server['php_self']}?currentpage=$prevpage'><</a> ";<br> } // end if <br>  // loop show links range of pages around current page<br> ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {<br>    // if it's valid page number...<br>    if (($x > 0) && ($x <= $totalpages)) {<br>       // if we're on current page...<br>       if ($x == $currentpage) {<br>          // 'highlight' don't make link<br>          echo " [<b>$x</b>] ";<br>       // if not current page...<br>       } else {<br>          // make link<br>          echo " <a href='{$_server['php_self']}?currentpage=$x'>$x</a> ";<br>       } // end else<br>    } // end if <br> } // end for<br>  // if not on last page, show forward , last page links   <br>      if ($currentpage != $totalpages) {<br>    // next page<br>    $nextpage = $currentpage + 1;<br>     // echo forward link next page <br>    echo " <a href='{$_server['php_self']}?currentpage=$nextpage'>></a> ";<br>    // echo forward link lastpage    echo " <a href='{$_server['php_self']}?currentpage=$totalpages'>>></a> ";<br> } // end if<br> /****** end build pagination links ******/<br> ?> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -