How to split a table into page nr1, pagenr2, pagenr3 etc. with PHP -
i have code works can not split table different pages. (page1, page2, page3 etc. same table continues on each page...)
here looks like. http://test.mehmetakb.se/test1.jpg
here code.
is easy want?
<!doctype html> <html lang="sv-se"/> <head> <meta charset="utf-8"/> <title>images</title> <style media="screen" type="text/css"> tr {display: inline-block;} #gallery { height: 510px; width: 670px; background-color: grey; margin-left: auto; margin-right: auto; text-align: center; display-align: center; } table { margin: 0 auto; border-spacing: 30px 3px; } </style> </head> <body> <div id="gallery"> <?php $mysqli = new mysqli('localhost', 'root', '', 'images'); echo "<table>"; $sql = "select * table1"; $result = $mysqli->query($sql); while($myrow = $result->fetch_array()) { echo "<div id='container'>"; echo "<tr>"; echo "<td><a href='./display2.php?number=".$myrow["number"]."'> <img src=".$myrow["image"]." height='100' width='100'> </a> </td>"; echo "<td style='display: block;'><a href='./item.php?produktid=".$myrow["number"]."'> <h4>".$myrow["name"]."</h4></a> </td>"; echo "</tr>"; echo "</div>"; } echo "</table>" ?> </div> </body> </html>
thank much. works now. pure image/product gallery can use want.
<!doctype html> <html lang="sv-se"/> <head> <meta charset="utf-8"/> <title>images</title> <style media="screen" type="text/css"> tr {display: inline-block;} #gallery { height: 710px; width: 670px; background-color: grey; margin-left: auto; margin-right: auto; text-align: center; display-align: center; } table { margin: 0 auto; border-spacing: 30px 3px; } body{font-family:"trebuchet ms", arial, helvetica, sans-serif;} div#pagination_controls{font-size:21px;} div#pagination_controls > a{ color:#06f; } div#pagination_controls > a:visited{ color:#06f; } </style> </head> <body> <div id="gallery"> <?php $mysqli = new mysqli('localhost', 'root', '', 'images'); //the first query total count of rows $sql = "select count(number) table1"; $query = mysqli_query($mysqli, $sql); $row = mysqli_fetch_row($query); //$row = mysqli_fetch_row($result); //here have total row count $rows = $row[0]; //this number of results want displayed per page $page_rows = 9; // tells page number of our last page $last = ceil($rows/$page_rows); // makes sure $last cannot less 1 if($last < 1){ $last = 1; } // establish $pagenum variable $pagenum = 1; // pagenum url vars if present, else = 1 if(isset($_get['pn'])){ $pagenum = preg_replace('#[^0-9]#', '', $_get['pn']); } // makes sure page number isn't below 1, or more our $last page if ($pagenum < 1) { $pagenum = 1; } else if ($pagenum > $last) { $pagenum = $last; } // sets range of rows query chosen $pagenum $limit = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; // query again, grabbing 1 page worth of rows applying $limit $sql = "select * table1 order id desc $limit"; $query = mysqli_query($mysqli, $sql); // shows user page on, , total number of pages $textline1 = "produkter (<b>$rows</b>)"; $textline2 = "page <b>$pagenum</b> of <b>$last</b>"; // establish $paginationctrls variable $paginationctrls = ''; // if there more 1 page worth of results if($last != 1){ /* first check if on page one. if don't need link previous page or first page nothing. if aren't generate links first page, , previous page. */ if ($pagenum > 1) { $previous = $pagenum - 1; $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$previous.'">previous</a> '; // render clickable number links should appear on left of target page number for($i = $pagenum-4; $i < $pagenum; $i++){ if($i > 0){ $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$i.'">'.$i.'</a> '; } } } // render target page number, without being link $paginationctrls .= ''.$pagenum.' '; // render clickable number links should appear on right of target page number for($i = $pagenum+1; $i <= $last; $i++){ $paginationctrls .= '<a href="'.$_server['php_self'].'?pn='.$i.'">'.$i.'</a> '; if($i >= $pagenum+4){ break; } } // same above, checking if on last page, , generating "next" if ($pagenum != $last) { $next = $pagenum + 1; $paginationctrls .= ' <a href="'.$_server['php_self'].'?pn='.$next.'">next</a> '; } } $list = ''; echo "<table>"; //list out tables of image gallery $sql = "select * table1 order number desc $limit"; $result = $mysqli->query($sql); while($myrow = $result->fetch_array()) { echo "<div id='container'>"; echo "<tr>"; echo "<td><a href='./display2.php?number=".$myrow["number"]."'> <img src=".$myrow["image"]." height='100' width='100'> </a> </td>"; echo "<td style='display: block;'><a href='./item.php?produktid=".$myrow["number"]."'> <h4>".$myrow["name"]."</h4></a> </td>"; echo "</tr>"; echo "</div>"; } echo "</table>"; // close database connection mysqli_close($mysqli); ?> <!doctype html> <div> <h2><?php echo $textline1; ?> listade </h2> <p><?php echo $textline2; ?></p> <p><?php echo $list; ?></p> <div id="pagination_controls"><?php echo $paginationctrls; ?></div> </div> </div> </body>
Comments
Post a Comment