navigatie en search in één script
- if(isset($_REQUEST['search'])) etc. en
- .$_REQUEST['search']. in de hyperlink onderaan, maar de paginatelling onderaan klopt niet wanneer ik een search query doe (uiteraard). Maar hoe krijg ik dit voor elkaar?
<html>
<head></head>
<body bgcolor="#FFFFFF">
<form method="post" action="cat17_online.php">
<input type="text" name="search" size=25 maxlength=25>
<input type="Submit" name="Submit" value="Submit">
</form><br>
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
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
<?php
include "connect.php"; //verbinding maken
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
// toegevoegde code doormij
if(isset($_REQUEST['search'])){
$search=$_REQUEST['search'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
}
else
// tot hier
$query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
$sql = mysql_query($query) or die ( mysql_error( ) );
echo"<table width=\"100%\" border=0>";
while($row = mysql_fetch_array($sql)){
echo"<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">".$row['Familienaam']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">".$row['Auteur']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">".$row['Titel']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">".$row['Nummer']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">".$row['Prijs']."</td></tr>";
echo"<tr><td colspan=\"2\"><hr></td></tr>";
}
echo"</table><br>";
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page&search=".$_REQUEST['search']."\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>
include "connect.php"; //verbinding maken
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
// toegevoegde code doormij
if(isset($_REQUEST['search'])){
$search=$_REQUEST['search'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
}
else
// tot hier
$query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
$sql = mysql_query($query) or die ( mysql_error( ) );
echo"<table width=\"100%\" border=0>";
while($row = mysql_fetch_array($sql)){
echo"<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">".$row['Familienaam']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">".$row['Auteur']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">".$row['Titel']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">".$row['Nummer']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">".$row['Prijs']."</td></tr>";
echo"<tr><td colspan=\"2\"><hr></td></tr>";
}
echo"</table><br>";
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page&search=".$_REQUEST['search']."\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>
// tot hier
Na je else moet je wel accolades gebruiken op de juiste plekken.
Elmer
else // hier zou een accolade moeten staan na 'else'
// tot hier
$query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
$sql = mysql_query($query) or die ( mysql_error( ) );
echo"<table width=\"100%\" border=0>";
while($row = mysql_fetch_array($sql)){
echo"<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">".$row['Familienaam']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">".$row['Auteur']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">".$row['Titel']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">".$row['Nummer']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">".$row['Prijs']."</td></tr>";
echo"<tr><td colspan=\"2\"><hr></td></tr>";
} // hier sluit je hem af
else query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
je geen accolades nodig hebt. De '// tot hier ' staat niet in het echte script. Sorry, dat is niet duidelijk inderdaad
Ik snap wat je bedoelt. Dan zit de fout dus ergens anders. We zoeken door.
Elmer
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
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
<?php
error_reporting (E_ALL);
//verbinding maken
include "connect.php";
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if (isset($_GET['page'])) {
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
// toegevoegde code doormij
if (isset($_REQUEST['search'])) {
$search = $_REQUEST['search'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
} else {
$query = "SELECT * FROM cat17 LIMIT $offset, $rowsPerPage";
}
$sql = mysql_query($query) or die(mysql_error());
echo "<table width=\"100%\" border=0>";
while ($row = mysql_fetch_array($sql)) {
echo "<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">" . $row['Familienaam'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">" . $row['Auteur'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">" . $row['Titel'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">" . $row['Nummer'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">" . $row['Prijs'] . "</td></tr>";
echo "<tr><td colspan=\"2\"><hr></td></tr>";
}
echo "</table><br>";
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows / $rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1) {
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} else {
// we're on page one, don't enable 'previous' link
$prev = ' [Prev] ';
// nor 'first page' link
$first = ' [First Page] ';
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page&search=" . $_REQUEST['search'] . "\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} else {
// we're on the last page, don't enable 'next' link
$next = ' [Next] ';
// nor 'last page' link
$last = ' [Last Page] ';
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>
error_reporting (E_ALL);
//verbinding maken
include "connect.php";
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if (isset($_GET['page'])) {
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
// toegevoegde code doormij
if (isset($_REQUEST['search'])) {
$search = $_REQUEST['search'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
} else {
$query = "SELECT * FROM cat17 LIMIT $offset, $rowsPerPage";
}
$sql = mysql_query($query) or die(mysql_error());
echo "<table width=\"100%\" border=0>";
while ($row = mysql_fetch_array($sql)) {
echo "<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">" . $row['Familienaam'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">" . $row['Auteur'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">" . $row['Titel'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">" . $row['Nummer'] . "</td></tr>";
echo "<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">" . $row['Prijs'] . "</td></tr>";
echo "<tr><td colspan=\"2\"><hr></td></tr>";
}
echo "</table><br>";
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows / $rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1) {
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} else {
// we're on page one, don't enable 'previous' link
$prev = ' [Prev] ';
// nor 'first page' link
$first = ' [First Page] ';
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page&search=" . $_REQUEST['search'] . "\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} else {
// we're on the last page, don't enable 'next' link
$next = ' [Next] ';
// nor 'last page' link
$last = ' [Last Page] ';
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>
query = "SELECT COUNT(*) AS numrows FROM cat17";
alle rijen van de database geteld worden en daar wordt de paging op gebasseerd. Maar na een search querie wil je het nieuwe totaal van het aantal rijen weten zodat je daar per 30 records doorheen kan klikken. Is dit duidelijk?
Elmer
Dat lijkt me toch wel heel sterk. Een searchquery is een SELECT en die voegt niets toe en verwijdert ook niets.
Sorry, ja je hebt helemaal gelijk. Ik bedoel het resultaat na de search query.. daar wil je dan per 30 doorheen klikken (als het meer dan 30 records bevat)
Dan moet je de paginering niet baseren op de query met select count (*) maar op mysql_num_rows () van je zoekquery.
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
krijg je dus altijd 30 rijen.
Good night!
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<?php
$query = "
SELECT COUNT(1) AS aantal
FROM cat17
WHERE
Familienaam LIKE '%$search%' ||
Auteur LIKE '%$search%' ||
Titel LIKE '%$search%'";
?>
$query = "
SELECT COUNT(1) AS aantal
FROM cat17
WHERE
Familienaam LIKE '%$search%' ||
Auteur LIKE '%$search%' ||
Titel LIKE '%$search%'";
?>
Als je die uitvoert VOOR je zoekquery krijg je het totaal aantal resultaten als 'aantal'.
Top Jan! bedankt.
groet,
Elmer
Elmer:
Klopt, maar het is evengoed aan te raden om altijd accolades te gebruiken. Daardoor wordt het meteen goed duidelijk wat je bedoelt. In je oorspronkelijke code leek het vanwege de uitlijning ook of de coderegel buiten de else viel. Ook dat komt de duidelijkheid niet ten goede.dit kan alleen wanneer de stelling uit één regel bestaat. Als het meerdere regels zijn, zijn accolades wel verplicht.
Een fout die nogal eens wordt gemaakt is dat er op het script te debuggen een echo wordt tussengevoegd. De oorspronkelijke regel valt dan buiten de else en het wordt maar al te vaak vergeten accolades om het blok heen te zetten. Je bent dan vaak lang bezig je debug-code te debuggen.
Gewijzigd op 17/01/2006 13:21:00 door Willem vp
Bedankt voor de tip! Ik ga er op letten.
Het is mogelijk om op alfabet (a|b|c|etc.) te sorteren, op trefwoord te zoeken, en natuurlijk om gewoon door de data heen te klikken
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
104
105
106
107
108
109
110
111
112
113
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
104
105
106
107
108
109
110
111
112
113
<?php
include "connect.php"; //verbinding maken
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
if(isset($_REQUEST['letter'])) // Zoeken op letter
{
$letter = $_REQUEST['letter'];
$query = "SELECT COUNT(1) AS numrows FROM cat17 WHERE Familienaam LIKE '$letter%'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '$letter%' LIMIT $offset, $rowsPerPage";
}
else if(isset($_REQUEST['search'])) // Zoeken op trefwoord
{
$search=$_REQUEST['search'];
$query = "SELECT COUNT(1) AS numrows FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
}
else // laat zien
{
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
}
$sql = mysql_query($query) or die ( mysql_error( ) );
echo"<table width=\"100%\" border=0>";
while($row = mysql_fetch_array($sql)){
echo"<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">".$row['Familienaam']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">".$row['Auteur']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">".$row['Titel']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">".$row['Nummer']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">".$row['Prijs']."</td></tr>";
echo"<tr><td colspan=\"2\"><hr></td></tr>";
}
echo"</table><br>";
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : null;
$letter = isset($_REQUEST['letter']) ? $_REQUEST['letter'] : null;
$prev = " <a href=\"$self?page=$page&search=$search&letter=$letter\">[Prev]</a> ";
$first = " <a href=\"$self?page=1&search=$search&letter=$letter\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : null;
$letter = isset($_REQUEST['letter']) ? $_REQUEST['letter'] : null;
$next = " <a href=\"$self?page=$page&search=$search&letter=$letter\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage&search=$search&letter=$letter\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>
include "connect.php"; //verbinding maken
// how many rows to show per page
$rowsPerPage = 30;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
if(isset($_REQUEST['letter'])) // Zoeken op letter
{
$letter = $_REQUEST['letter'];
$query = "SELECT COUNT(1) AS numrows FROM cat17 WHERE Familienaam LIKE '$letter%'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '$letter%' LIMIT $offset, $rowsPerPage";
}
else if(isset($_REQUEST['search'])) // Zoeken op trefwoord
{
$search=$_REQUEST['search'];
$query = "SELECT COUNT(1) AS numrows FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17 WHERE Familienaam LIKE '%$search%' || Auteur LIKE '%$search%' || Titel LIKE '%$search%' LIMIT $offset, $rowsPerPage";
}
else // laat zien
{
$query = "SELECT COUNT(*) AS numrows FROM cat17";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$query = "SELECT * FROM cat17"." LIMIT $offset, $rowsPerPage";
}
$sql = mysql_query($query) or die ( mysql_error( ) );
echo"<table width=\"100%\" border=0>";
while($row = mysql_fetch_array($sql)){
echo"<tr><td width=\"130\" valign=\"top\"><b>Familienaam:</b></td><td valign=\"top\">".$row['Familienaam']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Auteur:</b></td><td valign=\"top\">".$row['Auteur']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Titel:</b></td><td valign=\"top\">".$row['Titel']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Nummer:</b></td><td valign=\"top\">".$row['Nummer']."</td></tr>";
echo"<tr><td valign=\"top\"><b>Prijs:</b></td><td valign=\"top\">".$row['Prijs']."</td></tr>";
echo"<tr><td colspan=\"2\"><hr></td></tr>";
}
echo"</table><br>";
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : null;
$letter = isset($_REQUEST['letter']) ? $_REQUEST['letter'] : null;
$prev = " <a href=\"$self?page=$page&search=$search&letter=$letter\">[Prev]</a> ";
$first = " <a href=\"$self?page=1&search=$search&letter=$letter\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : null;
$letter = isset($_REQUEST['letter']) ? $_REQUEST['letter'] : null;
$next = " <a href=\"$self?page=$page&search=$search&letter=$letter\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage&search=$search&letter=$letter\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<table width=\"100%\"><tr><td>" . $first . $prev . "</td><td align=\"center\"> Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages </td><td align=\"right\">" . $next . $last . "</td></tr></table>";
?>