Pagina's
Ik ben de laatste tijd aan het knooien met pagina's.
Zo ziet mijn code eruit
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
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
<?php
$tbl_name1="tablename";
$adjacents1 = 3;
$query1 = "SELECT COUNT(*) as num1 FROM $tbl_name1 WHERE type='2' AND active='1' ORDER BY date DESC";
$total_pages1 = mysql_fetch_array(mysql_query($query1));
$total_pages1 = $total_pages1[num1];
$targetpage1 = "book.php";
$limit1 = 10;
$linkpage = $_GET['linkpage'];
if($linkpage)
$start1 = ($linkpage - 1) * $limit1;
else
$start1 = 0;
$sql2 = "SELECT * FROM $tbl_name1 WHERE type='2' AND active='1' ORDER BY date DESC LIMIT $start1, $limit1";
$result3 = mysql_query($sql2);
if ($linkpage == 0) $linkpage = 1;
$prev1 = $linkpage - 1;
$next1 = $linkpage + 1;
$lastpage1 = ceil($total_pages1/$limit1);
$lpm11 = $lastpage1 - 1;
$pagination1 = "";
if($lastpage1 > 1)
{
$pagination1 .= "<div class=\"pagination\" align=\"center\">";
//previous button
if ($linkpage > 1)
$pagination1.= "<a href=\"$targetpage1?linkpage=$prev1\">« Vorige</a>";
else
$pagination1.= "<span class=\"disabled\"></span>";
//pages
if ($lastpage1 < 7 + ($adjacents1 * 2))
{
for ($counter1 = 1; $counter1 <= $lastpage1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
}
elseif($lastpage1 > 5 + ($adjacents1 * 2))
{
if($linkpage < 1 + ($adjacents1 * 2))
{
for ($counter1 = 1; $counter1 < 4 + ($adjacents1 * 2); $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
$pagination1.= "...";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lpm11\">$lpm11</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lastpage1\">$lastpage1</a>";
}
elseif($lastpage1 - ($adjacents1 * 2) > $linkpage && $linkpage > ($adjacents1 * 2))
{
$pagination1.= "<a href=\"$targetpage1?linkpage=1\">1</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=2\">2</a>";
$pagination1.= "...";
for ($counter1 = $linkpage - $adjacents1; $counter1 <= $linkpage + $adjacents1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
$pagination1.= "...";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lpm11\">$lpm11</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lastpage1\">$lastpage1</a>";
}
else
{
$pagination1.= "<a href=\"$targetpage1?linkpage=1\">1</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=2\">2</a>";
$pagination1.= "...";
for ($counter1 = $lastpage1 - (2 + ($adjacents1 * 2)); $counter1 <= $lastpage1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
}
}
//next button
if ($linkpage < $counter1 - 1)
$pagination1.= "<a href=\"$targetpage1?linkpage=$next1\">Volgende »</a>";
else
$pagination1.= "<span class=\"disabled\"></span>";
$pagination1.= "</div>\n";
}
$nr1 = $start1;
if(mysql_num_rows($result3) > 0){
while ($row1 = mysql_fetch_array($result3))
{
?>
$tbl_name1="tablename";
$adjacents1 = 3;
$query1 = "SELECT COUNT(*) as num1 FROM $tbl_name1 WHERE type='2' AND active='1' ORDER BY date DESC";
$total_pages1 = mysql_fetch_array(mysql_query($query1));
$total_pages1 = $total_pages1[num1];
$targetpage1 = "book.php";
$limit1 = 10;
$linkpage = $_GET['linkpage'];
if($linkpage)
$start1 = ($linkpage - 1) * $limit1;
else
$start1 = 0;
$sql2 = "SELECT * FROM $tbl_name1 WHERE type='2' AND active='1' ORDER BY date DESC LIMIT $start1, $limit1";
$result3 = mysql_query($sql2);
if ($linkpage == 0) $linkpage = 1;
$prev1 = $linkpage - 1;
$next1 = $linkpage + 1;
$lastpage1 = ceil($total_pages1/$limit1);
$lpm11 = $lastpage1 - 1;
$pagination1 = "";
if($lastpage1 > 1)
{
$pagination1 .= "<div class=\"pagination\" align=\"center\">";
//previous button
if ($linkpage > 1)
$pagination1.= "<a href=\"$targetpage1?linkpage=$prev1\">« Vorige</a>";
else
$pagination1.= "<span class=\"disabled\"></span>";
//pages
if ($lastpage1 < 7 + ($adjacents1 * 2))
{
for ($counter1 = 1; $counter1 <= $lastpage1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
}
elseif($lastpage1 > 5 + ($adjacents1 * 2))
{
if($linkpage < 1 + ($adjacents1 * 2))
{
for ($counter1 = 1; $counter1 < 4 + ($adjacents1 * 2); $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
$pagination1.= "...";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lpm11\">$lpm11</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lastpage1\">$lastpage1</a>";
}
elseif($lastpage1 - ($adjacents1 * 2) > $linkpage && $linkpage > ($adjacents1 * 2))
{
$pagination1.= "<a href=\"$targetpage1?linkpage=1\">1</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=2\">2</a>";
$pagination1.= "...";
for ($counter1 = $linkpage - $adjacents1; $counter1 <= $linkpage + $adjacents1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
$pagination1.= "...";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lpm11\">$lpm11</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=$lastpage1\">$lastpage1</a>";
}
else
{
$pagination1.= "<a href=\"$targetpage1?linkpage=1\">1</a>";
$pagination1.= "<a href=\"$targetpage1?linkpage=2\">2</a>";
$pagination1.= "...";
for ($counter1 = $lastpage1 - (2 + ($adjacents1 * 2)); $counter1 <= $lastpage1; $counter1++)
{
if ($counter1 == $linkpage)
$pagination1.= "<span class=\"current\">$counter1</span>";
else
$pagination1.= "<a href=\"$targetpage1?linkpage=$counter1\">$counter1</a>";
}
}
}
//next button
if ($linkpage < $counter1 - 1)
$pagination1.= "<a href=\"$targetpage1?linkpage=$next1\">Volgende »</a>";
else
$pagination1.= "<span class=\"disabled\"></span>";
$pagination1.= "</div>\n";
}
$nr1 = $start1;
if(mysql_num_rows($result3) > 0){
while ($row1 = mysql_fetch_array($result3))
{
?>
Het probleem is nu. Als ik op volgende klik dan krijg ik een witte pagina. De hij moet dan naar pagina book.php nextpage gaan.
Ziet iemand hier zo een knullige fout?
Notice: Undefined index: linkpage in
dat is;
Nummer 2;
Notice: Use of undefined constant num1 - assumed 'num1' in
Ik zie er niks fouts aan.
Toevoeging op 05/04/2012 11:29:16:
Bij de linkpage heb ik het volgende van gemaakt maar dat haalt ook niks uit
Code (php)
1
2
3
2
3
<?php
$pagination1.= "<a href=\"$targetpage1?linkpage=$next1\">Volgende »</a>";
?>
$pagination1.= "<a href=\"$targetpage1?linkpage=$next1\">Volgende »</a>";
?>
Maar dan krijg ik gelijk Notice: Undefined index: linkpage in bij de eerste $linkpage.
Blijkbaar heb je voor je isset() nog een $_GET['linkpage'] staan?
Nee dat staat er niet boven. Alleen een $_GET['page'] Maar dat is van een andere tabel op dezelfde pagina.
Heb je wel een else gedaan? Dan is je $_GET linkpage dus niet meegestuurd..
veranderd naar dit:
Zoals Gerhard al aangaf? Wat jij deed klopte namelijk niet.
Krijg je dan nog steeds de fout, zet dan dit even bovenaan zodat je weet wat er precies in je GET array zit:
Naja ik herschrijf de hele pagina wel.