Kod
<?php session_start();
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
$wholeonly = false;
if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
?>
<html>
<head>
<title>nazwiska</title>
<meta name="generator" http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2><center><font size="6">xxxxxxxxxxxxx</font></center></h2></td></tr></table>
<?php
$conn = connect();
$showrecs = 50;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
switch ($a) {
case "view":
viewrec($recid);
break;
default:
select();
break;
}
if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;
mysql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="href">xxxxxxxxxxxxxxx</td></tr></table>
</body>
</html>
<?php function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;
if ($a == "reset") {
$filter = "";
$filterfield = "";
$wholeonly = "";
$order = "";
$ordtype = "";
}
$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Table: nazwiskoimie</td></tr>
<tr><td>Liczba rekordów <?php echo $startrec + 1 ?> - <?php echo $reccount ?> z <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="nazwiskoimie.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Custom Filter</b> </td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Wszystkie pola</option>
<option value="<?php echo "imie" ?>"<?php if ($filterfield == "imie") { echo "selected"; } ?>><?php echo htmlspecialchars("imie") ?></option>
<option value="<?php echo "nazwisko" ?>"<?php if ($filterfield == "nazwisko") { echo "selected"; } ?>><?php echo htmlspecialchars("nazwisko") ?></option>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Tylko całe słowa</td>
</td></tr>
<tr>
<td> </td>
<td><input type="submit" name="action" value="Szukaj"></td>
<td><a href="nazwiskoimie.php?a=reset">Reset</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr"> </td>
<td class="hr"><a class="hr" href="nazwiskoimie.php?order=<?php echo "imie" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("imie") ?></a></td>
<td class="hr"><a class="hr" href="nazwiskoimie.php?order=<?php echo "nazwisko" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("nazwisko") ?></a></td>
</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr>
<td class="<?php echo $style ?>"><a href="nazwiskoimie.php?a=view&recid=<?php echo $i ?>">Więcej</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["imie"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nazwisko"]) ?></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>
<?php function showrow($row, $recid)
{
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("imie")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["imie"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("nazwisko")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nazwisko"]) ?></td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<?php if ($page > 1) { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $page - 1 ?>"><< Poprzedni</a> </td>
<?php } ?>
<?php
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="nazwiskoimie.php?page=<?php echo $page + 1 ?>">Następny >></a> </td>
<?php } ?>
</tr>
</table>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="nazwiskoimie.php">Tabela główna</a></td>
<?php if ($recid > 0) { ?>
<td><a href="nazwiskoimie.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Poprzedni rekord</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="nazwiskoimie.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Następny rekord</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>
<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<?php
mysql_free_result($res);
} ?>
<?php function connect()
{
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("nazwiska");
return $conn;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT `id`, `imie`, `nazwisko` FROM `nazwiskoimie`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`imie` like '" .$filterstr ."') or (`nazwisko` like '" .$filterstr ."')";
}
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM `nazwiskoimie`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`imie` like '" .$filterstr ."') or (`nazwisko` like '" .$filterstr ."')";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
} ?>
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
$wholeonly = false;
if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
?>
<html>
<head>
<title>nazwiska</title>
<meta name="generator" http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2><center><font size="6">xxxxxxxxxxxxx</font></center></h2></td></tr></table>
<?php
$conn = connect();
$showrecs = 50;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
switch ($a) {
case "view":
viewrec($recid);
break;
default:
select();
break;
}
if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;
mysql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="href">xxxxxxxxxxxxxxx</td></tr></table>
</body>
</html>
<?php function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;
if ($a == "reset") {
$filter = "";
$filterfield = "";
$wholeonly = "";
$order = "";
$ordtype = "";
}
$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Table: nazwiskoimie</td></tr>
<tr><td>Liczba rekordów <?php echo $startrec + 1 ?> - <?php echo $reccount ?> z <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="nazwiskoimie.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Custom Filter</b> </td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Wszystkie pola</option>
<option value="<?php echo "imie" ?>"<?php if ($filterfield == "imie") { echo "selected"; } ?>><?php echo htmlspecialchars("imie") ?></option>
<option value="<?php echo "nazwisko" ?>"<?php if ($filterfield == "nazwisko") { echo "selected"; } ?>><?php echo htmlspecialchars("nazwisko") ?></option>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Tylko całe słowa</td>
</td></tr>
<tr>
<td> </td>
<td><input type="submit" name="action" value="Szukaj"></td>
<td><a href="nazwiskoimie.php?a=reset">Reset</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr"> </td>
<td class="hr"><a class="hr" href="nazwiskoimie.php?order=<?php echo "imie" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("imie") ?></a></td>
<td class="hr"><a class="hr" href="nazwiskoimie.php?order=<?php echo "nazwisko" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("nazwisko") ?></a></td>
</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr>
<td class="<?php echo $style ?>"><a href="nazwiskoimie.php?a=view&recid=<?php echo $i ?>">Więcej</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["imie"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nazwisko"]) ?></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>
<?php function showrow($row, $recid)
{
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("imie")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["imie"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("nazwisko")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nazwisko"]) ?></td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<?php if ($page > 1) { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $page - 1 ?>"><< Poprzedni</a> </td>
<?php } ?>
<?php
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="nazwiskoimie.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="nazwiskoimie.php?page=<?php echo $page + 1 ?>">Następny >></a> </td>
<?php } ?>
</tr>
</table>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="nazwiskoimie.php">Tabela główna</a></td>
<?php if ($recid > 0) { ?>
<td><a href="nazwiskoimie.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Poprzedni rekord</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="nazwiskoimie.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Następny rekord</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>
<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<?php
mysql_free_result($res);
} ?>
<?php function connect()
{
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("nazwiska");
return $conn;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT `id`, `imie`, `nazwisko` FROM `nazwiskoimie`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`imie` like '" .$filterstr ."') or (`nazwisko` like '" .$filterstr ."')";
}
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM `nazwiskoimie`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`imie` like '" .$filterstr ."') or (`nazwisko` like '" .$filterstr ."')";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
} ?>
Problem tkwi w paginacji a dokładniej gdy w bazie było niewiele rekordów paginacja sprawdzała się natomiast gdy baza zaczęła mieścić co raz więcej rekordów pojawił się problem gdyż paginacja kolejnych stron zaczęła się rozrastać
Próbowałem kombinować ze zmianami lecz to nic nie dało. Chciałbym by paginacja wyglądała np 1 2 3 > >> tak jak to jest na forum
Jeśli jest ktoś może mi pomóc w rozwiązaniu tego problemu będę wdzięczny o podpowiedz