De laagste waarde

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Non Actief

Non Actief

13/11/2011 19:59:22
Quote Anchor link
Hoi,
ik heb met behulp van SanThe op PHPhulp mijn programma eindelijk aan de gang gekregen,
nu loop ik alleen weer ergens tegen aan,
dit is mijn overzicht:

Afbeelding

en dit is mijn code (de herhalingscode van de tabel is verkort):

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php

$con
= mysql_connect('localhost', 'root', 'password') or die(mysql_error());
mysql_select_db('matman_test', $con) or die(mysql_error());
function
information($field)
{

    global $records_array;
    foreach($records_array as $record)
    {

        if($record[$field] == "" || $record[$field] == 0)
        {

            echo '<td class="empty">&nbsp;</td>';
        }

        else
        {
            echo '<td class="full">'.$record[$field].'</td>';
        }
    }
}

function
resources()
{

    global $records_array;
    $field_array = array('Currency', 'Grain', 'Grain2', 'WQ1(LC)', 'WQ1(G)', 'WQ2(LC)', 'WQ2(G)', 'WQ3(LC)', 'WQ3(G)', 'WQ4(LC)', 'WQ4(G)', 'WQ5(LC)', 'WQ5(G)', 'GQ1(LC)', 'GQ1(G)', 'GQ2(LC)', 'GQ2(G)', 'GQ3(LC)', 'GQ3(G)', 'GQ4(LC)', 'GQ4(G)', 'GQ5(LC)', 'GQ5(G)', 'FQ1(LC)', 'FQ1(G)', 'FQ2(LC)', 'FQ2(G)', 'FQ3(LC)', 'FQ3(G)', 'FQ4(LC)', 'FQ4(G)', 'FQ5(LC)', 'FQ5(G)');
    $query = mysql_query("SELECT * FROM resources");
    if(mysql_num_rows($query) != 0)
    {

        $records_array = array();
        while($data = mysql_fetch_assoc($query))
        {

            $records_array[] = $data;
        }

        echo '
        <table cellspacing="0" border="0" class="content">
        <tr>
            <td colspan="3">Land:</td>'
;
            foreach($records_array as $record)
            {

                echo '<td class="full">'.$record['Country'].'</td>';
            }

            echo '
        </tr>
        <tr class="test">
            <td align="center">Currency</td>
            <td colspan="2">LC in G</td>'
;
            $i = 0;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Grain:</td>
            <td>&nbsp;</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td align="center" rowspan="10">Weapons</td>
            <td rowspan="2">Q1</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q2</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q3</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q4</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q5</td>
            <td>LC</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            information($field_array[$i]);
            $i++;
            echo '
        </tr>
        </table>
        '
;
// enzovoort
    }
}

?>

<html>
<head>
<title>e-sim resources module</title>
<link rel="stylesheet" href="css/stylesheet.css" media="screen" />
</head>
<body>
<?php

resources();

?>

<br />
<a href="insert.php">Invoegen</a>
</body>
</html>


Zoals te zien is in het plaatje zijn het best veel waardes,
nu zou ik graag in een keer willen zien welke van de waardes in elke rij het laagste is.
Helaas krijg ik dit zelf niet voor elkaar.
Ik heb het geprobeerd met SQL, maar ik weet ook niet precies waar ik dit stukje code dan moet plaatsen :S
Zou iemand me hierbij kunnen helpen?
Gewijzigd op 13/11/2011 20:05:42 door Non Actief
 
PHP hulp

PHP hulp

28/03/2024 22:45:58
 
- SanThe -

- SanThe -

13/11/2011 20:31:52
Quote Anchor link
In een rij (horizontaal) of in een kolom (vertikaal)?
 
Non Actief

Non Actief

13/11/2011 20:45:17
Quote Anchor link
Elke rij(horizontaal)
 
- SanThe -

- SanThe -

13/11/2011 21:22:01
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function information($field)
{

    global $records_array;
    $lowest = 0;
    foreach($records_array as $record)
    {

        if($record[$field] == "" || $record[$field] == 0)
        {

            echo '<td class="empty">&nbsp;</td>';
        }

        else
        {
            if($record[$field] < $lowest or $lowest == 0)
            {

                $lowest = $record[$field];
            }

            echo '<td class="full">'.$record[$field].'</td>';
        }
    }

    return $lowest;
}

?>


Function gewijzigd.

Aanroep zo en je hebt de waarde in $lowest.
$lowest = information($field_array[$i]);
Gewijzigd op 13/11/2011 21:22:43 door - SanThe -
 
Non Actief

Non Actief

13/11/2011 21:35:31
Quote Anchor link
Heb de code aangepast,
maar ik krijg hem nog niet aan de praat.

Afbeelding

Met code:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php

$con
= mysql_connect('localhost', 'root', 'password') or die(mysql_error());
mysql_select_db('matman_test', $con) or die(mysql_error());
function
information($field)
{

    global $records_array;
    $lowest = 0;
    foreach($records_array as $record)
    {

        if($record[$field] == "" || $record[$field] == 0)
        {

            echo '<td class="empty">&nbsp;</td>';
        }

        else
        {
            if($record[$field] < $lowest or $lowest == 0)
            {

                $lowest = $record[$field];
            }

            if($record[$field] == $lowest)
            {

                echo '<td class="low">'.$record[$field].'</td>';
            }

            else
            {
                echo '<td class="full">'.$record[$field].'</td>';
            }
        }
    }

    return $lowest;
}

function
resources()
{

    global $records_array;
    $field_array = array('Currency', 'Grain', 'Grain2', 'WQ1(LC)', 'WQ1(G)', 'WQ2(LC)', 'WQ2(G)', 'WQ3(LC)', 'WQ3(G)', 'WQ4(LC)', 'WQ4(G)', 'WQ5(LC)', 'WQ5(G)', 'GQ1(LC)', 'GQ1(G)', 'GQ2(LC)', 'GQ2(G)', 'GQ3(LC)', 'GQ3(G)', 'GQ4(LC)', 'GQ4(G)', 'GQ5(LC)', 'GQ5(G)', 'FQ1(LC)', 'FQ1(G)', 'FQ2(LC)', 'FQ2(G)', 'FQ3(LC)', 'FQ3(G)', 'FQ4(LC)', 'FQ4(G)', 'FQ5(LC)', 'FQ5(G)');
    $query = mysql_query("SELECT * FROM resources");
    if(mysql_num_rows($query) != 0)
    {

        $records_array = array();
        while($data = mysql_fetch_assoc($query))
        {

            $records_array[] = $data;
        }

        echo '
        <table cellspacing="0" border="0" class="content">
        <tr>
            <td colspan="3">Land:</td>'
;
            foreach($records_array as $record)
            {

                echo '<td class="full">'.$record['Country'].'</td>';
            }

            echo '
        </tr>
        <tr class="test">
            <td align="center">Currency</td>
            <td colspan="2">LC in G</td>'
;
            $i = 0;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Grain:</td>
            <td>&nbsp;</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td align="center" rowspan="10">Weapons</td>
            <td rowspan="2">Q1</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q2</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q3</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q4</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td rowspan="2">Q5</td>
            <td>LC</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        <tr>
            <td>G</td>'
;
            $lowest = information($field_array[$i]);
            $i++;
            echo '
        </tr>
        </table>
        '
;
// enzovoort
    }
}

?>

<html>
<head>
<title>e-sim resources module</title>
<link rel="stylesheet" href="css/stylesheet.css" media="screen" />
</head>
<body>
<?php

resources();

?>

<br />
<a href="insert.php">Invoegen</a>
</body>
</html>
 
- SanThe -

- SanThe -

13/11/2011 21:50:55
Quote Anchor link
Aha, nu weet ik hoe je het wilt gebruiken.

Function geheel gewijzigd:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
function information($field)
{

    global $records_array;
    $lowest = 0;
    $temp = array();
    foreach($records_array as $record)
    {

        $temp[] = $record[$field];
        if($record[$field] != 0 and ($record[$field] < $lowest or $lowest == 0))
        {

            $lowest = $record[$field];
        }
    }

    foreach($temp as $value)
    {

        if($value != 0)
        {

            if($value == $lowest)
            {

                echo '<td class="low">'.$value.'</td>';
            }

            else
            {
                echo '<td class="full">'.$value.'</td>';
            }
        }

        else
        {
            echo '<td class="empty">&nbsp;</td>';
        }
    }
}

?>


Aanroep kan dan weer gewoon zo:
information($field_array[$i]);
 
Non Actief

Non Actief

13/11/2011 21:56:44
Quote Anchor link
Hij doet het! :D
Echt helemaal geweldig!
Uit interesse:
doe je dit als werk? :P
 
Kumkwat Trender

Kumkwat Trender

13/11/2011 22:00:16
Quote Anchor link
waarom tabellen ughh
 
- SanThe -

- SanThe -

13/11/2011 22:06:09
Quote Anchor link
Matthijs Veldhuizen op 13/11/2011 21:56:44:
Hij doet het! :D
Echt helemaal geweldig!
Uit interesse:
doe je dit als werk? :P


Nee, hobby. Was het maar zo.

Kumkwat Trender op 13/11/2011 22:00:16:
waarom tabellen ughh


Omdat divjes hier een beetje onzinnig zouden zijn. Dit is data die perfect gewoon in een tabel past.
Gewijzigd op 13/11/2011 22:07:12 door - SanThe -
 
Non Actief

Non Actief

13/11/2011 22:08:36
Quote Anchor link
Harstikke bedankt!
Had niet verwacht dat je dit als hobby zou doen :P
 
Synaps Framework

Synaps Framework

14/11/2011 10:12:48
Quote Anchor link
@Kumkwat Trender, heb jij jezelf aangeleerd om bij elk stuk code welke je ook maar iets van tabellen ziet te gaan miepen over divjes?

Hier worden tabellen op de juiste manier gebruikt. Divjes is overkill en je maakt het jezelf extra moeilijk.
Gewijzigd op 14/11/2011 10:13:10 door Synaps Framework
 
Bart V B

Bart V B

14/11/2011 10:26:04
Quote Anchor link
Tabellen zijn voor tabulaire data.
Oftewel, in een oog opslag zichtbare uitkomst.
En zo aan het plaatje te zien is dat het geval.
Dus tabellen voor dit gebruiken is de juiste oplossing.
Gewijzigd op 14/11/2011 10:47:00 door Bart V B
 
Jaron T

Jaron T

14/11/2011 10:30:01
Quote Anchor link
Kumkwat Trender op 13/11/2011 22:00:16:
waarom tabellen ughh


leeks die andere leeks 'flamen'..
 
- Ariën  -
Beheerder

- Ariën -

14/11/2011 10:38:20
Quote Anchor link
Bart V B op 14/11/2011 10:26:04:
Tabellen zijn voor Trabeculaire data.

Wat voor data :+
 
Ozzie PHP

Ozzie PHP

14/11/2011 10:41:26
Quote Anchor link
Ik gok dat Bart "tabulaire" data bedoelt, maar dat z'n spellingscontrole te hard heeft ingegrepen ;)
 
Bart V B

Bart V B

14/11/2011 10:45:46
Quote Anchor link
hehe.. Soms zijn die automagische controles niet echt handig..
Maar die bedoelde ik dus. :)
Gewijzigd op 14/11/2011 10:47:49 door Bart V B
 
Ger van Steenderen
Tutorial mod

Ger van Steenderen

14/11/2011 16:15:33
Quote Anchor link
In SQL
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
SELECT LEAST(col1, col2, col3) AS low, * FROM resources ........
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.