Hello you all.
i made my first paging script and i wonder if some on might take a look at it and se if it’s any good or not?
If you may find any thing in the code that not is necessary or some thing that i can modifier sow my script can be better then please add it what i can change
here is it! Fell free to use it if any one likes it.
<?
include ("../../management/connectdb/mysqlcondbgk.php");
$list_type = "WHERE // enter db";
$view_pages = 10; // Amout of value to be listed at every page.
$limit_total_pages = 50; // Amout of maximum listed values.
$page = isset($_GET['page']) ? intval($_GET['page']) : 0; //Starts the page counter from 0.
$select_total_pages = " * FROM //enter DB $list_type LIMIT $limit_total_pages"; // count how mutch to be listed.
$query = mysql_query("SELECT $select_total_pages");
$userstatus = (mysql_num_rows($query) == 0) ? $inout='To make a search select a option!' : $inout='Sorry - no matches'; //
if(mysql_num_rows($query) > 0){
$pages = mysql_num_rows($query);
$start_page = ($page * $view_pages); // Linting count method
$total_pages = ceil($pages / $view_pages); // The total sum of how many pages there are.
$total_pages >= 1 ? $list_start = $_GET['page'] + 1 : $list_start = 0; // jag är en fuskis
$result = mysql_query("SELECT * FROM // enter db $list_type LIMIT $start_page, $view_pages"); // Counts where where to start and end the limit.
$result_total = mysql_query("SELECT * FROM // enter db $list_type"); // Counts how many hits it finds
if (mysql_num_rows($result) > 0) {
echo '<br><br><center><b>Page '.$list_start. ' of '. $total_pages .' pages / Total hits: ' .mysql_num_rows($result_total). '</center></b><br>';
while ($row = mysql_fetch_array($result)) {
// run list value
}
echo '<br><center><b>Page '.$list_start. ' of '. $total_pages .' pages / Total hits: ' .mysql_num_rows($result_total). '</center></b>';
echo '<br><center>';
if ($page > 0) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?\">[<<]</a> ";
echo "<a href=\"{$_SERVER['PHP_SELF']}?&page=".($page-1)."\">[<]</a>\n"; }
else{
echo "[<<] ";
echo "[<]\n";
}
echo ' || ';
$max_url_list_per_page = 30; // Set amout of url to list
$end_url_list = $_GET['page'] + $max_url_list_per_page - 1; //
if($total_pages - 1 > 0) {
for($i = $_GET['page']; $i <= min($end_url_list,$total_pages - 1); $i++) {
if($i == $page) {
echo " " . ($i + 1) . " ";
} else {
echo " <a href=\"{$_SERVER['PHP_SELF']}?&page=$i\">" . ($i + 1) . "</a> ";
}
}
} else {
echo " 1 ";
}
echo ' || ';
if ($page <= $total_pages - 1 - $max_url_list_per_page) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?&page=".($page+1)."\">[>]</a>\n";
echo "<a href=\"{$_SERVER['PHP_SELF']}?&page=".($total_pages - 1)."\">[>>]</a> ";
}
else{
echo "[>] ";
echo "[>>]\n";
}
echo '</center>';
echo "<br>\n";
}
}else{
echo "<CENTER><BR><B><BR><BR><BR><BR>".$userstatus."</CENTER>";
}
?>