undefined k and page
ik heb een probleem met me search engine met pagination het geeft steeds undefined page of k maar ik heb het al aan gegeven
hier is de html code
Quote:
<form name="form" action="search.php" method="POST">
<input type="text" name="k" autocomplete="off" class="autosuggest" > <input type="submit" value="search">
<div class="dropdown">
<ul class="result"></ul>
</div>
</form>
<input type="text" name="k" autocomplete="off" class="autosuggest" > <input type="submit" value="search">
<div class="dropdown">
<ul class="result"></ul>
</div>
</form>
en dit is de php code
Quote:
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
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
<?php
mysql_connect ("localhost", "root", "");
mysql_select_db("results");
$k = $_POST['k'];
$tableName="search";
$targetpage = "search.php";
$limit = 1;
$terms = explode (" ", $k);
$query = "SELECT COUNT(*) as num FROM search WHERE " ;
foreach ($terms as $each){
@$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM search LIMIT $start, $limit";
$result = mysql_query($query1);
$query = mysql_query ($query);
$numrows = mysql_num_rows ($query);
foreach ($terms as $each){
@$i++;
if ($i == 1)
$query1 .= "keywords LIKE '%$each%' ";
else
$query1 .= "OR keywords LIKE '%$each%' ";
}
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
echo "<p><font color='#62472C'>$total_pages Result(s)</font> </p>";
// pagination
echo $paginate;
?>
mysql_connect ("localhost", "root", "");
mysql_select_db("results");
$k = $_POST['k'];
$tableName="search";
$targetpage = "search.php";
$limit = 1;
$terms = explode (" ", $k);
$query = "SELECT COUNT(*) as num FROM search WHERE " ;
foreach ($terms as $each){
@$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM search LIMIT $start, $limit";
$result = mysql_query($query1);
$query = mysql_query ($query);
$numrows = mysql_num_rows ($query);
foreach ($terms as $each){
@$i++;
if ($i == 1)
$query1 .= "keywords LIKE '%$each%' ";
else
$query1 .= "OR keywords LIKE '%$each%' ";
}
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
echo "<p><font color='#62472C'>$total_pages Result(s)</font> </p>";
// pagination
echo $paginate;
?>
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
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
<?
$conclose= mysql_connect ("localhost", "root", "");
mysql_select_db("results");
if ($numrows > 0) {
while ($row = mysql_fetch_assoc($result)){
$id = $row ['id'];
$title = $row ['title'];
$image = $row ['image'];
$keywords = $row ['keywords'];
$link = $row ['link'];
echo "<div class='floater'> <h3><a href ='$link'><img src='$image' width='180px' height='140px'><br /><font color='#62472C'>$title</font></a></h3></div>";
}
}
else
echo "<p><font color='#62472C'>No games found for: $k </font></p>";
?>
$conclose= mysql_connect ("localhost", "root", "");
mysql_select_db("results");
if ($numrows > 0) {
while ($row = mysql_fetch_assoc($result)){
$id = $row ['id'];
$title = $row ['title'];
$image = $row ['image'];
$keywords = $row ['keywords'];
$link = $row ['link'];
echo "<div class='floater'> <h3><a href ='$link'><img src='$image' width='180px' height='140px'><br /><font color='#62472C'>$title</font></a></h3></div>";
}
}
else
echo "<p><font color='#62472C'>No games found for: $k </font></p>";
?>
Kun je iets specifieker zijn? Je plaatst een code van circa 200 regels :')
of Undefined index: page in C:\xampp\htdocs\search.php on line 149
dus ik denk dat het met de html code get and post te maken heeft kan iemand me daarmee helpen
Daniyal hussain op 15/07/2012 14:41:17:
het geeft steed Notice: Undefined index: k in C:\xampp\htdocs\search.php on line 127
of Undefined index: page in C:\xampp\htdocs\search.php on line 149
dus ik denk dat het met de html code get and post te maken heeft kan iemand me daarmee helpen
of Undefined index: page in C:\xampp\htdocs\search.php on line 149
dus ik denk dat het met de html code get and post te maken heeft kan iemand me daarmee helpen
Regel 5 en regel 27:
$k = $_POST['k'];
$page = mysql_escape_string($_GET['page']);
Je controleert niet of er daadwerkelijk ook wat in $_POST['k'] en $_GET['page'] zit.
Edit:
probeer eens var_dump($_GET); en var_dump($_POST); dan zie je wat er in zit.
Gewijzigd op 15/07/2012 14:47:11 door Kumkwat Trender