Mysql order button
Bijvoorbeeld:
Dit is nu mijn orderning
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY `id` ASC LIMIT 2000");
Dan klik ik op de knop en dan veranderd het in:
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY `date` ASC LIMIT 2000");
Zou iemand mij hiermee kunnen helpen?
Alvast bedankt.
Ik weet de situatie niet, maar als het om een lijst gaat, zou ik eerder voor GET kiezen. Zo voorkom je dat je steeds opnieuw POST-waardes staat te versturen als je terug in de URL-historie gaat.
Dit is wat ik nu heb...
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY `id` ASC LIMIT 2000");
?>
<input type="radio" name="ordering" id="type" value="class" checked="yes"/> Media-type<br/>
<?
if(isset($_GET['ordering'])) {
maar wat hier moet weet ik niet...
}
?>
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY `id` ASC LIMIT 2000");
?>
<input type="radio" name="ordering" id="type" value="class" checked="yes"/> Media-type<br/>
<?
if(isset($_GET['ordering'])) {
maar wat hier moet weet ik niet...
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'date':
$sort = 'date';
break;
default:
$sort = 'id';
break;
}
case 'id':
$sort = 'id';
break;
case 'date':
$sort = 'date';
break;
default:
$sort = 'id';
break;
}
En dan kan je met $sort de juiste waarde ophalen. Wegens veiligheids-maatregelen haal ik de waarde niet direct uit GET. Zo voorkom ik ongewenste sorteringen, en vermijd ik SQL-injection.
Gewijzigd op 25/03/2013 17:27:29 door - Ariën -
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY `id` ASC LIMIT 2000");
want dit kan niet: $result = mysql_query("SELECT * FROM `bestanden` ORDER BY $sort ASC LIMIT 2000");
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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum" checked="yes"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd" checked="yes"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur" checked="yes"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size" checked="yes"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id" checked="yes"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class" checked="yes"/> Media-type<br/>
</div>
</div>
<?
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
?>
<div class="timeline">
<?
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY $sort ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?
}
?>
</div>
</div>
<?
dbClose($db);
?>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum" checked="yes"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd" checked="yes"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur" checked="yes"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size" checked="yes"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id" checked="yes"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class" checked="yes"/> Media-type<br/>
</div>
</div>
<?
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
?>
<div class="timeline">
<?
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY $sort ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?
}
?>
</div>
</div>
<?
dbClose($db);
?>
</body>
</html>
Maar dit werkt nog niet wat doe ik verkeerd?
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
Ohw ja klopt dom van me ... Maar ik heb dit nu aangepast maar er gebeurt nog steeds niks... iemand tips?
Als deze niet bestaat dan is je query niet compleet.
Ook mis ik tevens foutafhandeling op je query, en zie ik de short-tags in PHP, gebruik liever <?php en ?>
Gewijzigd op 26/03/2013 11:56:15 door - Ariën -
Ik zie geen waarde in de URL nee... Hoe kan ik deze controle uitvoeren? Zou je een voorbeeld kunnen geven?
Code (php)
Gewijzigd op 26/03/2013 12:08:32 door - Ariën -
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
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
<? veranderd in [code]<?php , wat doe ik nog verkeerd (sorry voor de vele vragen ik probeer hier wijzer uit te komen).
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Media-type:</b><br/>
<div class="checkboxbox">
<input type="checkbox" id="pdf" value="pdf" checked="yes"/> PDF <br/>
<input type="checkbox" id="boek" value="boek" checked="yes"/> Boeken <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="DVD" value="DVD" checked="yes"/> DVD's <br/>
<input type="checkbox" id="video" value="video's" checked="yes"/> Video's <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="audio" value="audio" checked="yes"/> audio <br/>
<input type="checkbox" id="website" value="website" checked="yes"/> Website <br/>
</div>
</div>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
<?php
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
<script>
$(document).ready(function() {
$("#pdf").click(function () {
if ($(".pdf").is(":hidden")) {
$(".pdf").show("fast");
} else {
$(".pdf").hide("fast");
}
});
$("#boek").click(function () {
if ($(".boek").is(":hidden")) {
$(".boek").show("fast");
} else {
$(".boek").hide("fast");
}
});
$("#DVD").click(function () {
if ($(".DVD").is(":hidden")) {
$(".DVD").show("fast");
} else {
$(".DVD").hide("fast");
}
});
$("#video").click(function () {
if ($(".video").is(":hidden")) {
$(".video").show("fast");
} else {
$(".video").hide("fast");
}
});
$("#audio").click(function () {
if ($(".audio").is(":hidden")) {
$(".audio").show("fast");
} else {
$(".audio").hide("fast");
}
});
$("#website").click(function () {
if ($(".website").is(":hidden")) {
$(".website").show("fast");
} else {
$(".website").hide("fast");
}
});
});
</script>
</body>
</html>
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Media-type:</b><br/>
<div class="checkboxbox">
<input type="checkbox" id="pdf" value="pdf" checked="yes"/> PDF <br/>
<input type="checkbox" id="boek" value="boek" checked="yes"/> Boeken <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="DVD" value="DVD" checked="yes"/> DVD's <br/>
<input type="checkbox" id="video" value="video's" checked="yes"/> Video's <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="audio" value="audio" checked="yes"/> audio <br/>
<input type="checkbox" id="website" value="website" checked="yes"/> Website <br/>
</div>
</div>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
<?php
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
<script>
$(document).ready(function() {
$("#pdf").click(function () {
if ($(".pdf").is(":hidden")) {
$(".pdf").show("fast");
} else {
$(".pdf").hide("fast");
}
});
$("#boek").click(function () {
if ($(".boek").is(":hidden")) {
$(".boek").show("fast");
} else {
$(".boek").hide("fast");
}
});
$("#DVD").click(function () {
if ($(".DVD").is(":hidden")) {
$(".DVD").show("fast");
} else {
$(".DVD").hide("fast");
}
});
$("#video").click(function () {
if ($(".video").is(":hidden")) {
$(".video").show("fast");
} else {
$(".video").hide("fast");
}
});
$("#audio").click(function () {
if ($(".audio").is(":hidden")) {
$(".audio").show("fast");
} else {
$(".audio").hide("fast");
}
});
$("#website").click(function () {
if ($(".website").is(":hidden")) {
$(".website").show("fast");
} else {
$(".website").hide("fast");
}
});
});
</script>
</body>
</html>
Wat je nu doet is alleen maar controleren wat de waarde van de ordering in de URl is, en of deze wel meegegeven is.
Je moet nu nog een form om je selectvelden plaatsen, en je form de method GET meegeven.
Gewijzigd op 26/03/2013 12:23:27 door - Ariën -
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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Media-type:</b><br/>
<div class="checkboxbox">
<input type="checkbox" id="pdf" value="pdf" checked="yes"/> PDF <br/>
<input type="checkbox" id="boek" value="boek" checked="yes"/> Boeken <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="DVD" value="DVD" checked="yes"/> DVD's <br/>
<input type="checkbox" id="video" value="video's" checked="yes"/> Video's <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="audio" value="audio" checked="yes"/> audio <br/>
<input type="checkbox" id="website" value="website" checked="yes"/> Website <br/>
</div>
</div>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
</form>
<?php
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
<script>
$(document).ready(function() {
$("#pdf").click(function () {
if ($(".pdf").is(":hidden")) {
$(".pdf").show("fast");
} else {
$(".pdf").hide("fast");
}
});
$("#boek").click(function () {
if ($(".boek").is(":hidden")) {
$(".boek").show("fast");
} else {
$(".boek").hide("fast");
}
});
$("#DVD").click(function () {
if ($(".DVD").is(":hidden")) {
$(".DVD").show("fast");
} else {
$(".DVD").hide("fast");
}
});
$("#video").click(function () {
if ($(".video").is(":hidden")) {
$(".video").show("fast");
} else {
$(".video").hide("fast");
}
});
$("#audio").click(function () {
if ($(".audio").is(":hidden")) {
$(".audio").show("fast");
} else {
$(".audio").hide("fast");
}
});
$("#website").click(function () {
if ($(".website").is(":hidden")) {
$(".website").show("fast");
} else {
$(".website").hide("fast");
}
});
});
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Timeline</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="none"/>
<meta name="author" content="Marco Hendriks"/>
<meta name="audience" content="none"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<?php
if (!function_exists("dbConnect")) {
include 'database/config.php';
include 'database/lib.php';
}
$db = dbConnect();
?>
<div id="wrapper">
<h2/>Newmedia-reader timeline</h2>
<div class="checkboxwrapper">
<b>Media-type:</b><br/>
<div class="checkboxbox">
<input type="checkbox" id="pdf" value="pdf" checked="yes"/> PDF <br/>
<input type="checkbox" id="boek" value="boek" checked="yes"/> Boeken <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="DVD" value="DVD" checked="yes"/> DVD's <br/>
<input type="checkbox" id="video" value="video's" checked="yes"/> Video's <br/>
</div>
<div class="checkboxbox">
<input type="checkbox" id="audio" value="audio" checked="yes"/> audio <br/>
<input type="checkbox" id="website" value="website" checked="yes"/> Website <br/>
</div>
</div>
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
</form>
<?php
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
<script>
$(document).ready(function() {
$("#pdf").click(function () {
if ($(".pdf").is(":hidden")) {
$(".pdf").show("fast");
} else {
$(".pdf").hide("fast");
}
});
$("#boek").click(function () {
if ($(".boek").is(":hidden")) {
$(".boek").show("fast");
} else {
$(".boek").hide("fast");
}
});
$("#DVD").click(function () {
if ($(".DVD").is(":hidden")) {
$(".DVD").show("fast");
} else {
$(".DVD").hide("fast");
}
});
$("#video").click(function () {
if ($(".video").is(":hidden")) {
$(".video").show("fast");
} else {
$(".video").hide("fast");
}
});
$("#audio").click(function () {
if ($(".audio").is(":hidden")) {
$(".audio").show("fast");
} else {
$(".audio").hide("fast");
}
});
$("#website").click(function () {
if ($(".website").is(":hidden")) {
$(".website").show("fast");
} else {
$(".website").hide("fast");
}
});
});
</script>
</body>
</html>
Dat gaat niet zomaar vanzelf....
De url veranderd nu in:
http://localhost/newmedia-reader/index2.php?ordering=class&submit=Submit
alleen de mysql order veranderd nog niet.
Dit is wat ik nu heb:
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
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
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if (isset($_GET['submit'])) {
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if (isset($_GET['submit'])) {
if(isset($_GET['ordering'])) {
switch($_GET['ordering']) {
case 'id':
$sort = 'id';
break;
case 'class':
$sort = 'class';
break;
default:
$sort = 'id';
break;
}
} else {
$sort = 'id'; // als er geen ID is meegegeven, sorteer dan hierop...
}
}
?>
<div class="timeline">
<?php
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY '".$sort."' ASC LIMIT 2000");
$num_rows = mysql_num_rows($result);
$aantal = count($num_rows);
while($row = mysql_fetch_array($result)){
?>
<a href="#"><div class="<?echo $row['class'];?>"><?echo $row['id'];?></div></a>
<?php
}
?>
</div>
</div>
<?
dbClose($db);
?>
Overigens is die submit niet eens verplicht in de URL, je kan ook je name uit je submit knop weglaten.
Gewijzigd op 26/03/2013 12:39:52 door - Ariën -
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<div class="checkboxwrapper">
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div><!-- hoort bij "checkboxwrapper" die de parent is van het form -->
<input type="submit" name="submit" value="Submit"/>
</form>
<b>Ordening:</b><br/>
<form action="index2.php" method="GET">
<div class="checkboxbox">
<input type="radio" name="ordering" id="datum" value="datum"/> Upload datum <br/>
<input type="radio" name="ordering" id="tijd" value="tijd"/> Tijd <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="auteur" value="auteur"/> Auteur<br/>
<input type="radio" name="ordering" id="size" value="size"/> Bestandsgrootte <br/>
</div>
<div class="checkboxbox">
<input type="radio" name="ordering" id="nummer" value="id"/> ID<br/>
<input type="radio" name="ordering" id="class" value="class"/> Media-type<br/>
</div>
</div><!-- hoort bij "checkboxwrapper" die de parent is van het form -->
<input type="submit" name="submit" value="Submit"/>
</form>
Je sluit je form dus af NA de wrapper. Dit kan niet.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<form action="index2.php" method="post">
<input type="hidden" name="test" value="class" />
<input type="submit" value="Media-type">
</form>
<?php
if(isset($_POST['test'])) {
$test = mysql_real_escape_string($_POST['test']);
} else {
$test = 'id';
}
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY $test ASC LIMIT 2000");
?>
<input type="hidden" name="test" value="class" />
<input type="submit" value="Media-type">
</form>
<?php
if(isset($_POST['test'])) {
$test = mysql_real_escape_string($_POST['test']);
} else {
$test = 'id';
}
$result = mysql_query("SELECT * FROM `bestanden` ORDER BY $test ASC LIMIT 2000");
?>
Bedankt allemaal voor de reacties en hulp :)
Toch opgestapt op POST? persoonlijk zou ik GET meer aanraden, voor al mensen in de URL-historie terug gaan, om die POST-bevestigingsschermen over te slaan.