Zoek paging
Ik wil graag paginering hebben met mijn sql database.
Onderstaande werkt wel als een zoekterm vooraf is ingevuld, zie $input
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
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
<?
if (!@mysql_select_db(\"database\", @mysql_connect(\"localhost\", \"user\", \"pass\")))
{
echo \"Er kan geen database connectie gemaakt worden.\";
exit();
}
$page_name=\"found.php\"; // If you use this code with a different page ( or file ) name then change this
@$column_name=$_GET[\'image_date\']; // Read the column name from query string.
$start=$_GET[\'start\']; // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$input = zoekwoord;
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=\" SELECT * FROM table WHERE column LIKE \'%$input%\' \";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=\" SELECT * FROM table WHERE column LIKE \'%$input%\' \";
if(isset($column_name) and strlen($column_name)>0){
$query = $query . \" order by $column_name\";
}
$query = $query. \" limit $eu, $limit \";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($row = mysql_fetch_array($result))
{
echo \"<tr >\";
echo \"<td class=head2 align=left id=\'title\'><table class=head2 cellspacing=0><tr><td valign=top>
<table class=head2 cellspacing=0>
<tr><td colspan=2 width=285>$row[image_name]</td></tr>
</table>
</td><td valign=top></td>\";
echo \"</tr>\";
}
echo \"\";
////////////////////////////// End of displaying the table with records ////////////////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo \"<tr><td class=head0>\";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print \"<a href=\'$page_name?start=$back&column_name=$column_name\'>Prev</a>\";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo \"<!--</td><td class=head0 align=center width=\'30%\'>-->\";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo \" <a href=\'$page_name?start=$i&column_name=$column_name\'>$l</a> \";
}
else { echo \"<font face=\'Verdana\' color=red>$l</font>\";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}
echo \"<!--</td><td class=head0>-->\";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print \"<a href=\'$page_name?start=$next&column_name=$column_name\'>Next</a>\";}
echo \"</td></tr>\";
?>
if (!@mysql_select_db(\"database\", @mysql_connect(\"localhost\", \"user\", \"pass\")))
{
echo \"Er kan geen database connectie gemaakt worden.\";
exit();
}
$page_name=\"found.php\"; // If you use this code with a different page ( or file ) name then change this
@$column_name=$_GET[\'image_date\']; // Read the column name from query string.
$start=$_GET[\'start\']; // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$input = zoekwoord;
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=\" SELECT * FROM table WHERE column LIKE \'%$input%\' \";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=\" SELECT * FROM table WHERE column LIKE \'%$input%\' \";
if(isset($column_name) and strlen($column_name)>0){
$query = $query . \" order by $column_name\";
}
$query = $query. \" limit $eu, $limit \";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($row = mysql_fetch_array($result))
{
echo \"<tr >\";
echo \"<td class=head2 align=left id=\'title\'><table class=head2 cellspacing=0><tr><td valign=top>
<table class=head2 cellspacing=0>
<tr><td colspan=2 width=285>$row[image_name]</td></tr>
</table>
</td><td valign=top></td>\";
echo \"</tr>\";
}
echo \"\";
////////////////////////////// End of displaying the table with records ////////////////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo \"<tr><td class=head0>\";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print \"<a href=\'$page_name?start=$back&column_name=$column_name\'>Prev</a>\";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo \"<!--</td><td class=head0 align=center width=\'30%\'>-->\";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo \" <a href=\'$page_name?start=$i&column_name=$column_name\'>$l</a> \";
}
else { echo \"<font face=\'Verdana\' color=red>$l</font>\";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}
echo \"<!--</td><td class=head0>-->\";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print \"<a href=\'$page_name?start=$next&column_name=$column_name\'>Next</a>\";}
echo \"</td></tr>\";
?>
</table>
Door het script te veranderen zodat ik d.m.v. van een search invul veld een trefwoord in typ lukt dat gedeeltelijk; de eerste 10 treffers worden getoond maar niet het vervolg. (De tweede select quiry werkt dat niet) Ik heb hopeloos het web afgezocht en het lijkt of ik er dicht bij ben. Maar telkens komen ze iets te kort. Voorbeeld: als paginering wel lukt dan werkt LIKE niet.
Ik heb ook voorbeelden van dit forum getest, maar ze zijn telkens weer anders, en dat is zeer verwarrend voor een leek.
Iemand een idee?
groeten
Er zijn nog geen reacties op dit bericht.