Hulp voor Pagination gevraagd
Ik ben op het moment bezig met OOP Pagination. Alles werkt prima behalve 1 ding. Als ik op vorige druk bij de pagination balk gaat de pagina mooi van bijv pagina 2 naar 1.
maar als ik volgende drukt om naar de volgende pagina te gaan, krijg ik ineens de melding "De query niet goed ontvangen." ik heb zelf geen idee waarom die melding er komt...
Ik hoop dat jullie misschien mij even een tip kan geven of een duwtje in de juiste richting.
Hier is de code die ik dusver heb
-------------------------------------------------------------
weergeven producten
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
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
<?php
require_once('pagination_class.php');
require_once ('product_class.php');
if( isset( $_GET['page']))
{
$page = $_GET["page"];
}
else
{
$page = 1;
}
$per_page = 4;
$total_count = $product::count_all();
// $total_count = 4;
//echo $total_count;
$pagination = new Pagination( $page, $per_page, $total_count);
if(isset ($_GET['action']))
{
//echo"test1234";
switch ( $_GET["action"])
{
case"verwijderen":
$product::remove_from_product( $_GET["id"]);
header("localtion:weergeven_producten.php?page='.$page");
echo"verwijder record";
break;
default:
}
}
else
{
$product::find_all_limit_offset($pagination->get_per_page(), $pagination->offset() );
}
if ( $pagination->has_prev_page())
{
?>
require_once('pagination_class.php');
require_once ('product_class.php');
if( isset( $_GET['page']))
{
$page = $_GET["page"];
}
else
{
$page = 1;
}
$per_page = 4;
$total_count = $product::count_all();
// $total_count = 4;
//echo $total_count;
$pagination = new Pagination( $page, $per_page, $total_count);
if(isset ($_GET['action']))
{
//echo"test1234";
switch ( $_GET["action"])
{
case"verwijderen":
$product::remove_from_product( $_GET["id"]);
header("localtion:weergeven_producten.php?page='.$page");
echo"verwijder record";
break;
default:
}
}
else
{
$product::find_all_limit_offset($pagination->get_per_page(), $pagination->offset() );
}
if ( $pagination->has_prev_page())
{
?>
<a href =weergeven_producten.php?page=
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
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
<?php
echo $pagination ->prev_page().">prev </a>";
}
else
{
//echo $pagination->total_pages();
}
for ($i = 1; $i <= $pagination->total_pages(); $i++)
{
//<a href="weergeven_producten.php?page=2'
if($i == $page)
{
echo"<a href='weergeven_producten.php?page=".$i."'><b> ".$i." </b></a>";
}
else
{
echo"<a href='weergeven_producten.php?page=".$i."'> ".$i." </a>";
}
}
if ( $pagination->has_next_page())
{
?>
echo $pagination ->prev_page().">prev </a>";
}
else
{
//echo $pagination->total_pages();
}
for ($i = 1; $i <= $pagination->total_pages(); $i++)
{
//<a href="weergeven_producten.php?page=2'
if($i == $page)
{
echo"<a href='weergeven_producten.php?page=".$i."'><b> ".$i." </b></a>";
}
else
{
echo"<a href='weergeven_producten.php?page=".$i."'> ".$i." </a>";
}
}
if ( $pagination->has_next_page())
{
?>
<a href =weergeven_producten.php?page=
Code (php)
-------------------------------------------------------------
product class
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
//echo"test";
include_once("MySQLDatabase_class.php");
$product = new product_class();
class product_class
{
//fields
private $id;
private $merk;
private $productnaam;
private $prijs;
private $fotonaam;
//properties
public function get_id(){return $this->id;}
public function get_merk(){return $this->merk;}
public function get_productnaam(){return $this->productnaam;}
public function get_prijs(){return $this->prijs;}
public function get_offset(){return $this->offset;}
public function get_limit(){return $this->limit;}
//public function get_fotonaam(){return $this->fotonaam;}
//constructor
public function __construct($id='', $productnaam='', $merk='', $prijs='')
{
$this->id =$id;
$this->productnaam =$productnaam;
$this->merk =$merk;
$this->prijs =$prijs;
//$this->fotonaam =$fotonaam.'';
}
//methods
public static function find_by_sql( $query )
{
global $database;
$result_set= $database->fire_query( $query );
// echo"test2";
$user_array = array();
while ( $row = mysqli_fetch_array($result_set))
{
$object = new product_class();
$object->id = $row["id"];
$object->productnaam = $row ["productnaam"];
$object->merk = $row["merk"];
$object->prijs = $row ["prijs"];
$user_array[] = $object;
}
return $user_array;
}
public static function remove_from_product( $id )
{
global $database;
$query = "delete from `producten` where `id` = '".$id."'";
$database->fire_query($query);
}
/* public static function find_all()
{
$query = "select * from 'producten'";
$return self::find_by_sql($query);
}*/
Public static function find_by_id( $id)
{
$query = "select * from `product` where `id` = '".$id."'";
array_shift(self::find_by_sql( $query));
}
public static function find_all_limit_offset( $limit, $offset)
{
$query = " SELECT * FROM `producten` " . " LIMIT $offset, $limit";
echo"<table border='1'>
<tr>
<th>id</td>
<th>productnaam</td>
<th>merk</td>
<th>prijs</td>
<th>verwijder</td>
<tr/>";
foreach ( self::find_by_sql($query) as $product)
{
echo" <tr>
<td>".$product->id."</td>
<td>".$product->productnaam."</td>
<td>".$product->merk."</td>
<td>".$product->prijs."</td>
<td><a href='weergeven_producten.php?action=verwijderen&id=".$product->id."'> X </a></td>
</tr>";
}
echo"</table>";}
public static function uploaden_foto($fotonaam)
{
$mime_type= array('image/jpeg',
'image/pjpeg',
'image/png',
'image/gif',
'image/x-png');
if(in_array( $fotonaam['type'], $mime_type))
{
if( !file_exists($dir))
{
mkdir($dir);
}
if( !file_exists($dir."thumbnails/"))
{
mkdir($dir."thumbnails/");
}
if (is_uploaded_file( $fotonaam['tmp_name']))
{
move_uploaded_file($fotonaam['tmp_name'], $dir.$fotonaam['name']) ;
}
}
else
{
echo"het geuploade bestand heeft een niet geoorloofde extensie";
}
}
/* public static function count_all()
{
global $database;
$query = "SELECT *
FROM `producten`
LIMIT 0 , 30 ";
$result = $database->fire_query($query);
return mysql_num_rows($result);
}*/
public static function count_all()
{
global $database;
$query = "select count(*) from `producten`";
$recordset = $database->fire_query($query);
$row = mysqli_fetch_array($recordset);
$aantal = array_shift($row);
return $aantal;
}
public static function upload_thumbnail ($fotonaam )
{
define("thumb_size", 80);
// $path_foto = "Plaatje/".$fotonaam["name"];
$path_foto = "plaatjes/".$fotonaam["name"];
$path_thumbnail = "plaatjes/thumbnails/tn_".$fotonaam["name"];
$foto_afmeting = getimagesize( $path_foto);
$foto_verhouding = $foto_afmeting[0]/$foto_afmeting[1];
if($foto_verhouding >= 1 )
{
$tn_height = thumb_size;
$tn_width = $tn_height * $foto_verhouding;
}
else
{
$tn_height = thumb_size;
$tn_width = $tn_height * $foto_verhouding;
}
switch ($fotonaam['type'])
{
case 'image/jpeg':
$surce = imagecreatefromjpeg($patch_foto);
imagecopyresampled ($thumb, $source, 0, 0, 0, 0, $tn_width,
$tn_heigth, $foto_afmeting[0],
$foto_afmeting[1]);
imagejpeg($thumb, $path_thumbnail, 100);
break;
default:
echo "het bestand met deze extensie kan niet worden geupload";
echo"<br />";
}
}
public static function insert_into_product($merk, $productnaam, $prijs, $fotonaam)
{
Global $database;
$query = "insert into 'producten'( 'id', 'merk', 'productnaam', 'prijs','fotonaam')
values ( null, '".$merk."','".$productnaam."','".$prijs."','".$fotonaam."')";
$database->fire_query($query);
}
}
?>
//echo"test";
include_once("MySQLDatabase_class.php");
$product = new product_class();
class product_class
{
//fields
private $id;
private $merk;
private $productnaam;
private $prijs;
private $fotonaam;
//properties
public function get_id(){return $this->id;}
public function get_merk(){return $this->merk;}
public function get_productnaam(){return $this->productnaam;}
public function get_prijs(){return $this->prijs;}
public function get_offset(){return $this->offset;}
public function get_limit(){return $this->limit;}
//public function get_fotonaam(){return $this->fotonaam;}
//constructor
public function __construct($id='', $productnaam='', $merk='', $prijs='')
{
$this->id =$id;
$this->productnaam =$productnaam;
$this->merk =$merk;
$this->prijs =$prijs;
//$this->fotonaam =$fotonaam.'';
}
//methods
public static function find_by_sql( $query )
{
global $database;
$result_set= $database->fire_query( $query );
// echo"test2";
$user_array = array();
while ( $row = mysqli_fetch_array($result_set))
{
$object = new product_class();
$object->id = $row["id"];
$object->productnaam = $row ["productnaam"];
$object->merk = $row["merk"];
$object->prijs = $row ["prijs"];
$user_array[] = $object;
}
return $user_array;
}
public static function remove_from_product( $id )
{
global $database;
$query = "delete from `producten` where `id` = '".$id."'";
$database->fire_query($query);
}
/* public static function find_all()
{
$query = "select * from 'producten'";
$return self::find_by_sql($query);
}*/
Public static function find_by_id( $id)
{
$query = "select * from `product` where `id` = '".$id."'";
array_shift(self::find_by_sql( $query));
}
public static function find_all_limit_offset( $limit, $offset)
{
$query = " SELECT * FROM `producten` " . " LIMIT $offset, $limit";
echo"<table border='1'>
<tr>
<th>id</td>
<th>productnaam</td>
<th>merk</td>
<th>prijs</td>
<th>verwijder</td>
<tr/>";
foreach ( self::find_by_sql($query) as $product)
{
echo" <tr>
<td>".$product->id."</td>
<td>".$product->productnaam."</td>
<td>".$product->merk."</td>
<td>".$product->prijs."</td>
<td><a href='weergeven_producten.php?action=verwijderen&id=".$product->id."'> X </a></td>
</tr>";
}
echo"</table>";}
public static function uploaden_foto($fotonaam)
{
$mime_type= array('image/jpeg',
'image/pjpeg',
'image/png',
'image/gif',
'image/x-png');
if(in_array( $fotonaam['type'], $mime_type))
{
if( !file_exists($dir))
{
mkdir($dir);
}
if( !file_exists($dir."thumbnails/"))
{
mkdir($dir."thumbnails/");
}
if (is_uploaded_file( $fotonaam['tmp_name']))
{
move_uploaded_file($fotonaam['tmp_name'], $dir.$fotonaam['name']) ;
}
}
else
{
echo"het geuploade bestand heeft een niet geoorloofde extensie";
}
}
/* public static function count_all()
{
global $database;
$query = "SELECT *
FROM `producten`
LIMIT 0 , 30 ";
$result = $database->fire_query($query);
return mysql_num_rows($result);
}*/
public static function count_all()
{
global $database;
$query = "select count(*) from `producten`";
$recordset = $database->fire_query($query);
$row = mysqli_fetch_array($recordset);
$aantal = array_shift($row);
return $aantal;
}
public static function upload_thumbnail ($fotonaam )
{
define("thumb_size", 80);
// $path_foto = "Plaatje/".$fotonaam["name"];
$path_foto = "plaatjes/".$fotonaam["name"];
$path_thumbnail = "plaatjes/thumbnails/tn_".$fotonaam["name"];
$foto_afmeting = getimagesize( $path_foto);
$foto_verhouding = $foto_afmeting[0]/$foto_afmeting[1];
if($foto_verhouding >= 1 )
{
$tn_height = thumb_size;
$tn_width = $tn_height * $foto_verhouding;
}
else
{
$tn_height = thumb_size;
$tn_width = $tn_height * $foto_verhouding;
}
switch ($fotonaam['type'])
{
case 'image/jpeg':
$surce = imagecreatefromjpeg($patch_foto);
imagecopyresampled ($thumb, $source, 0, 0, 0, 0, $tn_width,
$tn_heigth, $foto_afmeting[0],
$foto_afmeting[1]);
imagejpeg($thumb, $path_thumbnail, 100);
break;
default:
echo "het bestand met deze extensie kan niet worden geupload";
echo"<br />";
}
}
public static function insert_into_product($merk, $productnaam, $prijs, $fotonaam)
{
Global $database;
$query = "insert into 'producten'( 'id', 'merk', 'productnaam', 'prijs','fotonaam')
values ( null, '".$merk."','".$productnaam."','".$prijs."','".$fotonaam."')";
$database->fire_query($query);
}
}
?>
-------------------------------------------------------------
Pagination class
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
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
<?php
class Pagination
{
private $current_page;
private $per_page;
private $total_count;
//properties
public function get_per_page() {return $this->per_page;}
public function get_current_page() {return $this->current_page;}
public function get_total_count() {return $this->total_count;}
//constructor
public function total_pages()
{
return ceil ($this->total_count / $this->per_page);
//return ceil ($this->total_count / $this->$per_page);
}
public function __construct( $page, $per_page, $total_count )
{
$this->current_page = $page;
$this->per_page = $per_page;
$this->total_count = $total_count;
//echo $this->current_page."test dit is de pagination current page";
}
public function offset()
{
return ($this->current_page - 1) * $this->per_page;
}
public function next_page()
{
return ($this->current_page +1);
}
public function prev_page()
{
return ($this->current_page -1);
}
public function has_next_page()
{
return ($this->current_page < $this->total_pages() );
}
public function has_prev_page()
{
return ($this->current_page > 1 );
}
}
?>
class Pagination
{
private $current_page;
private $per_page;
private $total_count;
//properties
public function get_per_page() {return $this->per_page;}
public function get_current_page() {return $this->current_page;}
public function get_total_count() {return $this->total_count;}
//constructor
public function total_pages()
{
return ceil ($this->total_count / $this->per_page);
//return ceil ($this->total_count / $this->$per_page);
}
public function __construct( $page, $per_page, $total_count )
{
$this->current_page = $page;
$this->per_page = $per_page;
$this->total_count = $total_count;
//echo $this->current_page."test dit is de pagination current page";
}
public function offset()
{
return ($this->current_page - 1) * $this->per_page;
}
public function next_page()
{
return ($this->current_page +1);
}
public function prev_page()
{
return ($this->current_page -1);
}
public function has_next_page()
{
return ($this->current_page < $this->total_pages() );
}
public function has_prev_page()
{
return ($this->current_page > 1 );
}
}
?>
Zou je alleen RELEVANTE code willen plaatsen. Dit is echt veel te veel code.
probleem is al opgelost post kan gesloten worden