Data sorteren zonder query uit te voeren?
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
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
<?php
function get_items ($sort_by, $sort_order) {
$sql = "
SELECT id, name, projectleader, kindofproduct, brand, ETD, ETA, country
FROM proposal
ORDER BY " . $sort_by . " " . $sort_order;
if (!$res = mysql_query ($sql)) {
echo '<pre>';
echo htmlentities ($sql);
trigger_error (mysql_errno () . ': ' . mysql_error ());
echo '</pre>';
}
else {
if ($sort_order == 'ASC') {
$sort_order = 'DESC';
}
else {
$sort_order = 'ASC';
}
echo '<table align="center">';
echo '<tr>';
echo '<td><a href="?sort_by=name&sort_order='.$sort_order.'">Project name ▼</a></td>';
echo '<td><a href="?sort_by=projectleader&sort_order='.$sort_order.'">Project leader ▼</a></td>';
echo '<td><a href="?sort_by=kindofproduct&sort_order='.$sort_order.'">Kind of product ▼</a></td>';
echo '<td><a href="?sort_by=brand&sort_order='.$sort_order.'">Brand ▼</a></td>';
echo '<td>ETD</td>';
echo '<td>ETA</td>';
echo '<td>Exclusivity country</td>';
echo '<td>Project details</td>';
echo '</tr>';
while (list($id, $name, $projectleader, $kindofproduct, $brand, $ETD, $ETA, $country) = mysql_fetch_array ($res)) {
echo("<tr>
<td>$name</td>
<td>$projectleader</td>
<td>$kindofproduct</td>
<td>$brand</td>
<td>$ETD</td>
<td>$ETA</td>
<td>$country</td>
<td><a href=\"projectdetails.php?id=$id \">Project details</a></td>
\n");
}
echo '</table>';
}
}
$sort_by = (isset ($_GET['sort_by'])) ? ($_GET['sort_by']) : ('name');
$sort_by_toegestaan = array ('ID', 'name', 'projectleader', 'kindofproduct', 'brand');
if (!in_array ($sort_by, $sort_by_toegestaan)) {
$sort_by = 'name';
}
$sort_order = (isset ($_GET['sort_order'])) ? ($_GET['sort_order']) : ('ASC');
$sort_order_toegestaan = array ('ASC', 'DESC');
if (!in_array ($sort_order, $sort_order_toegestaan)) {
$sort_order = 'ASC';
}
?>
function get_items ($sort_by, $sort_order) {
$sql = "
SELECT id, name, projectleader, kindofproduct, brand, ETD, ETA, country
FROM proposal
ORDER BY " . $sort_by . " " . $sort_order;
if (!$res = mysql_query ($sql)) {
echo '<pre>';
echo htmlentities ($sql);
trigger_error (mysql_errno () . ': ' . mysql_error ());
echo '</pre>';
}
else {
if ($sort_order == 'ASC') {
$sort_order = 'DESC';
}
else {
$sort_order = 'ASC';
}
echo '<table align="center">';
echo '<tr>';
echo '<td><a href="?sort_by=name&sort_order='.$sort_order.'">Project name ▼</a></td>';
echo '<td><a href="?sort_by=projectleader&sort_order='.$sort_order.'">Project leader ▼</a></td>';
echo '<td><a href="?sort_by=kindofproduct&sort_order='.$sort_order.'">Kind of product ▼</a></td>';
echo '<td><a href="?sort_by=brand&sort_order='.$sort_order.'">Brand ▼</a></td>';
echo '<td>ETD</td>';
echo '<td>ETA</td>';
echo '<td>Exclusivity country</td>';
echo '<td>Project details</td>';
echo '</tr>';
while (list($id, $name, $projectleader, $kindofproduct, $brand, $ETD, $ETA, $country) = mysql_fetch_array ($res)) {
echo("<tr>
<td>$name</td>
<td>$projectleader</td>
<td>$kindofproduct</td>
<td>$brand</td>
<td>$ETD</td>
<td>$ETA</td>
<td>$country</td>
<td><a href=\"projectdetails.php?id=$id \">Project details</a></td>
\n");
}
echo '</table>';
}
}
$sort_by = (isset ($_GET['sort_by'])) ? ($_GET['sort_by']) : ('name');
$sort_by_toegestaan = array ('ID', 'name', 'projectleader', 'kindofproduct', 'brand');
if (!in_array ($sort_by, $sort_by_toegestaan)) {
$sort_by = 'name';
}
$sort_order = (isset ($_GET['sort_order'])) ? ($_GET['sort_order']) : ('ASC');
$sort_order_toegestaan = array ('ASC', 'DESC');
if (!in_array ($sort_order, $sort_order_toegestaan)) {
$sort_order = 'ASC';
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Karel
Dit is mogelijk... Wanneer je dat wilt sorteren die op het scherm staat, en je wilt dit doen vanuit de browser, zul je alleen client-side moeten gaan werken...
Het is dus mogelijk, maar dan niet met PHP... Ik weet niet hoe groot je javascript kennis is, maar ik zou eens zoeken naar scripts als: http://www.activewidgets.com/grid/ (let op, deze is niet gratis!)
Maar volgens mij geeft hij wel duidelijk weer wat je wilt, of niet?
ah bedankt, ik heb iets gevonden dat inderdaag met javascript werkt en waar ik niet voor hoef te betalen ;)