PHP Navigatie vraag
Ik heb een vraag hoe kan ik deze script toevoegen aan mijn website.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
function navigatie($currentpage,$totalpages,$url)
{
$output = '';
$output_num = '';
// both = 4 of meer
if (($currentpage - 4) > 0 && ($currentpage + 4) < $totalpages) {
for($a = ($currentpage-4);$a <= ($currentpage+4);$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
if (($currentpage - 4) == 1) {
$first = false;
} else {
$first = true;
}
if (($currentpage + 4) == $totalpages) {
$last = false;
} else {
$last = true;
}
// left = 4 of meer
} elseif (($currentpage - 4) > 0) {
$math = $totalpages - $currentpage;
$start_temp = 9 - $math;
$start = $currentpage - $start_temp;
if ($start < 1) {
$start = 1;
}
for($a = $start;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = true;
// right = 4 of meer
} elseif (($currentpage + 4) < $totalpages) {
if ($totalpages > 9) {
$loop = 9;
} else {
$loop = $totalpages;
}
for($a = 1;$a <= $loop;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = true;
$first = false;
// none = 4 of meer
} else {
for($a = 1;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = false;
}
if ($first == true) {
$output .= ' <b><a href="' . $url . '1">[eerste]</a></b> ';
}
if ($currentpage != 1) {
$output .= ' <b><a href="' . $url . ($currentpage-1) .' ">[vorige]</a></b> ';
}
$output .= " " . $output_num . " ";
if ($currentpage != $totalpages) {
$output .= ' <b><a href="' . $url . ($currentpage+1) . ' ">[volgende]</a></b> ';
}
if ($last == true) {
$output .= '<b><a href="' . $url . $totalpages . ' ">[laatste]</a></b> ';
}
return $output;
}
$itemsperpage = 25;
$totalrecords = 1000; // dit kan een aantal records zijn uit de database
$totalpages = ceil($totalrecords/$itemsperpage);
if (!IsSet($_GET['p'])) {
$currentpage = 1;
} else {
$currentpage = ceil($_GET['p']);
}
if ($currentpage < 1 || $currentpage > ceil($totalpages)) {
$output = 'Helaas, deze pagina bestaat niet.';
} else {
$output = navigatie($currentpage,$totalpages,'?p=');
$output .= '<br /><br />Pagina: ' . $currentpage;
}
?>
function navigatie($currentpage,$totalpages,$url)
{
$output = '';
$output_num = '';
// both = 4 of meer
if (($currentpage - 4) > 0 && ($currentpage + 4) < $totalpages) {
for($a = ($currentpage-4);$a <= ($currentpage+4);$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
if (($currentpage - 4) == 1) {
$first = false;
} else {
$first = true;
}
if (($currentpage + 4) == $totalpages) {
$last = false;
} else {
$last = true;
}
// left = 4 of meer
} elseif (($currentpage - 4) > 0) {
$math = $totalpages - $currentpage;
$start_temp = 9 - $math;
$start = $currentpage - $start_temp;
if ($start < 1) {
$start = 1;
}
for($a = $start;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = true;
// right = 4 of meer
} elseif (($currentpage + 4) < $totalpages) {
if ($totalpages > 9) {
$loop = 9;
} else {
$loop = $totalpages;
}
for($a = 1;$a <= $loop;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = true;
$first = false;
// none = 4 of meer
} else {
for($a = 1;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = false;
}
if ($first == true) {
$output .= ' <b><a href="' . $url . '1">[eerste]</a></b> ';
}
if ($currentpage != 1) {
$output .= ' <b><a href="' . $url . ($currentpage-1) .' ">[vorige]</a></b> ';
}
$output .= " " . $output_num . " ";
if ($currentpage != $totalpages) {
$output .= ' <b><a href="' . $url . ($currentpage+1) . ' ">[volgende]</a></b> ';
}
if ($last == true) {
$output .= '<b><a href="' . $url . $totalpages . ' ">[laatste]</a></b> ';
}
return $output;
}
$itemsperpage = 25;
$totalrecords = 1000; // dit kan een aantal records zijn uit de database
$totalpages = ceil($totalrecords/$itemsperpage);
if (!IsSet($_GET['p'])) {
$currentpage = 1;
} else {
$currentpage = ceil($_GET['p']);
}
if ($currentpage < 1 || $currentpage > ceil($totalpages)) {
$output = 'Helaas, deze pagina bestaat niet.';
} else {
$output = navigatie($currentpage,$totalpages,'?p=');
$output .= '<br /><br />Pagina: ' . $currentpage;
}
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
</head>
<body>
</body>
</html>
Dit is wat ik nu heb de knoppen Eerst Vorige Volgende Laatste, wou ik graag vervangen door cijfers (zie voorbeeld hier boven)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Flevoland = 25;
$pageNum_Flevoland = 0;
if (isset($_GET['pageNum_Flevoland'])) {
$pageNum_Flevoland = $_GET['pageNum_Flevoland'];
}
$startRow_Flevoland = $pageNum_Flevoland * $maxRows_Flevoland;
mysql_select_db($database_Proberen, $Proberen);
$query_Flevoland = "SELECT * FROM flevoland ORDER BY Plaats ASC, flevoland.Camping";
$query_limit_Flevoland = sprintf("%s LIMIT %d, %d", $query_Flevoland, $startRow_Flevoland, $maxRows_Flevoland);
$Flevoland = mysql_query($query_limit_Flevoland, $Proberen) or die(mysql_error());
$row_Flevoland = mysql_fetch_assoc($Flevoland);
if (isset($_GET['totalRows_Flevoland'])) {
$totalRows_Flevoland = $_GET['totalRows_Flevoland'];
} else {
$all_Flevoland = mysql_query($query_Flevoland);
$totalRows_Flevoland = mysql_num_rows($all_Flevoland);
}
$totalPages_Flevoland = ceil($totalRows_Flevoland/$maxRows_Flevoland)-1;
$queryString_Flevoland = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Flevoland") == false &&
stristr($param, "totalRows_Flevoland") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Flevoland = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Flevoland = sprintf("&totalRows_Flevoland=%d%s", $totalRows_Flevoland, $queryString_Flevoland);
?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Flevoland = 25;
$pageNum_Flevoland = 0;
if (isset($_GET['pageNum_Flevoland'])) {
$pageNum_Flevoland = $_GET['pageNum_Flevoland'];
}
$startRow_Flevoland = $pageNum_Flevoland * $maxRows_Flevoland;
mysql_select_db($database_Proberen, $Proberen);
$query_Flevoland = "SELECT * FROM flevoland ORDER BY Plaats ASC, flevoland.Camping";
$query_limit_Flevoland = sprintf("%s LIMIT %d, %d", $query_Flevoland, $startRow_Flevoland, $maxRows_Flevoland);
$Flevoland = mysql_query($query_limit_Flevoland, $Proberen) or die(mysql_error());
$row_Flevoland = mysql_fetch_assoc($Flevoland);
if (isset($_GET['totalRows_Flevoland'])) {
$totalRows_Flevoland = $_GET['totalRows_Flevoland'];
} else {
$all_Flevoland = mysql_query($query_Flevoland);
$totalRows_Flevoland = mysql_num_rows($all_Flevoland);
}
$totalPages_Flevoland = ceil($totalRows_Flevoland/$maxRows_Flevoland)-1;
$queryString_Flevoland = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Flevoland") == false &&
stristr($param, "totalRows_Flevoland") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Flevoland = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Flevoland = sprintf("&totalRows_Flevoland=%d%s", $totalRows_Flevoland, $queryString_Flevoland);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1" align="center">
<tr>
<td>Camping</td>
<td>Type</td>
<td>Plaats</td>
<td>Website (Ja/Nee)</td>
</tr>
<tr>
<td><a href="Camping.php?recordID="> </a> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<table border="0">
<tr>
<td>
<a href="">Eerst</a>
</td>
<td>
<a href="
Code (php)
</td>
<td>
<a href="
Code (php)
</td>
<td>
<a href="
Code (php)
1
<?php printf("%s?pageNum_Flevoland=%d%s", $currentPage, $totalPages_Flevoland, $queryString_Flevoland); ?>
</td>
</tr>
</table>
Records tot van
</body>
</html>
Groetjes A Jansen
Gewijzigd op 01/01/1970 01:00:00 door A Jansen