SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | $dbc = new mysqli("localhost", "root", "", "test");
| |
| 4 | $query = "SELECT * FROM `fisk`;"; | |
| 5 | ||
| 6 | if ($result = $dbc->query($query)) {
| |
| 7 | while ($row = $result->fetch_assoc()) {
| |
| 8 | $arr[] = array($row['K1'], $row['K2'], $row['K3']); | |
| 9 | } | |
| 10 | ||
| 11 | $result->close(); | |
| 12 | } | |
| 13 | ||
| 14 | $workingK1 = NULL; | |
| 15 | foreach ($arr as $index => $val) {
| |
| 16 | if ( ($workingK1 == NULL) || ($workingK1 != $val[0]) ) {
| |
| 17 | $workingK1 = $val[0]; | |
| 18 | $newArr[$workingK1] = array(0 => NULL, 1 => NULL, 2 => NULL); | |
| 19 | } | |
| 20 | ||
| 21 | - | if ($newArr[$workingK1][2] == NULL) {
|
| 21 | + | if ( ($newArr[$workingK1][2] == NULL) || ($arr[$index][2]) < ($newArr[$workingK1][2]) ) {
|
| 22 | $newArr[$workingK1][0] = $workingK1; | |
| 23 | $newArr[$workingK1][1] = $val[1]; | |
| 24 | - | $newArr[$workingK1][2] = $val[2]; |
| 24 | + | |
| 25 | } | |
| 26 | - | elseif ( ($arr[$index][2]) < ($newArr[$workingK1][2]) ) {
|
| 26 | + | |
| 27 | ||
| 28 | // Arrayet $newArr inneholder nΓ₯ en rad for hver unike K1, | |
| 29 | // hvor K3 er lavest. Alle feltene (K1, K2 og K3) er i et subarray. | |
| 30 | // | |
| 31 | // Her looper jeg igjennom alle resultatene | |
| 32 | echo ' | |
| 33 | <table style="border: 1px #000 solid;"> | |
| 34 | <tr> | |
| 35 | <td style="text-align: center;"><span style="font-weight: bold;">K1</span></td> | |
| 36 | <td style="text-align: center;"><span style="font-weight: bold;">K2</span></td> | |
| 37 | <td style="text-align: center;"><span style="font-weight: bold;">K3</span></td> | |
| 38 | </tr> | |
| 39 | '; | |
| 40 | foreach ($newArr as $newIndex => $newVal) {
| |
| 41 | echo '<tr>'; | |
| 42 | ||
| 43 | foreach ($newArr[$newIndex] as $subIndex => $subVal) {
| |
| 44 | echo ' | |
| 45 | <td style="text-align: center;">' . $subVal . '</td> | |
| 46 | '; | |
| 47 | } | |
| 48 | - | |
| 48 | + | |
| 49 | } | |
| 50 | echo '</table>' | |
| 51 | ||
| 52 | ?> |