De laagste waarde
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:
en dit is mijn code (de herhalingscode van de tabel is verkort):
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
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"> </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> </td>
<td>LC</td>';
information($field_array[$i]);
$i++;
echo '
</tr>
<tr>
<td> </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>
$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"> </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> </td>
<td>LC</td>';
information($field_array[$i]);
$i++;
echo '
</tr>
<tr>
<td> </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
In een rij (horizontaal) of in een kolom (vertikaal)?
Elke rij(horizontaal)
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
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"> </td>';
}
else
{
if($record[$field] < $lowest or $lowest == 0)
{
$lowest = $record[$field];
}
echo '<td class="full">'.$record[$field].'</td>';
}
}
return $lowest;
}
?>
function information($field)
{
global $records_array;
$lowest = 0;
foreach($records_array as $record)
{
if($record[$field] == "" || $record[$field] == 0)
{
echo '<td class="empty"> </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 -
maar ik krijg hem nog niet aan de praat.
Met code:
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
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"> </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> </td>
<td>LC</td>';
$lowest = information($field_array[$i]);
$i++;
echo '
</tr>
<tr>
<td> </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>
$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"> </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> </td>
<td>LC</td>';
$lowest = information($field_array[$i]);
$i++;
echo '
</tr>
<tr>
<td> </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>
Function geheel gewijzigd:
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
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"> </td>';
}
}
}
?>
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"> </td>';
}
}
}
?>
Aanroep kan dan weer gewoon zo:
information($field_array[$i]);
Echt helemaal geweldig!
Uit interesse:
doe je dit als werk? :P
waarom tabellen ughh
Matthijs Veldhuizen op 13/11/2011 21:56:44:
Hij doet het! :D
Echt helemaal geweldig!
Uit interesse:
doe je dit als werk? :P
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 -
Had niet verwacht dat je dit als hobby zou doen :P
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
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
Kumkwat Trender op 13/11/2011 22:00:16:
waarom tabellen ughh
leeks die andere leeks 'flamen'..
Ik gok dat Bart "tabulaire" data bedoelt, maar dat z'n spellingscontrole te hard heeft ingegrepen ;)
Maar die bedoelde ik dus. :)
Gewijzigd op 14/11/2011 10:47:49 door Bart V B