Native php tab package, the package only function, is applicable to all the tables

<? PHP
/ **
* package paging function
* $ table [String] table
* @ $ size [number] [number of pieces per page]
* /
function fenye (Table $, $ size)
{
$ = mysqli_connect Link ( "127.0.0.1", "root", "123456", "18test") or die ( " database connection failed!");
$ = SQL "SELECT * from Table $";
$ Result = the mysqli_query (Link $, $ SQL );
$ total = mysqli_num_rows ($ Result); // total number of
// $ size = 5; // number of per page
$ url = "pages.php"; // request the URL
$ P = isset ($ ? _GET [ "p"]) $ _GET [ "p"]: 1; // current page, the first page of the default
$ pages = ceil ($ total / $ size); // total number of pages
$ start = ($ p - 1) * $ size; // start position data to
$ = SQL "SELECT * from Table $ $ start limit, $ size";
$ Result = the mysqli_query ($ Link,SQL $);
$ the Next the p-+ 1 = $> = $ Pages and the Pages and the $: $ the p-+ 1; // Next?
? $ Prev = $ p - 1 <1 1: $ p - 1; // previous page

echo '<table border="1">';
while ($row = mysqli_fetch_row($result)) {
echo '<tr>';
foreach ($row as $col) {
echo '<td>' . $col . '</td>';
}
echo '</tr>';
}
echo '</table>';
echo "<div><a href='?p=1'>首页</a>;
<a href='?p=$prev'>上一页</a>
<a href='?p=$next'>下一页</a>
<a href='?p=$pages'>&nbsp;尾页</a>";
echo '</div>';
mysqli_close($link);
}

Guess you like

Origin www.cnblogs.com/cuijunling/p/12029750.html