Nieuws script veranderen
Mijn nieuws plaats hij onder elkaar, dus van Januari naar december. Wat betekend als je al vanaf Maart nieuws post en je nu weer nieuws post in Oktober, dat je helemaal naar beneden moet scrollen om het nieuws te lezen. Ik wil eigenlijk dat hij het nieuws anders om plaats. Het nieuwe bovenop, dus van nieuw naar oud.
Het gaat hier alleen om de maanden, in de maand komt het dag nieuws wel bovenaan te staan (nieuw en dan pas ouwd)
Kan iemand mij helpen?
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
172
173
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
172
173
<?
function maand($counter)
{
if ($counter == 1)
$count = "Januari";
elseif ($counter == 2)
$count = "Februari";
elseif ($counter == 3)
$count = "Maart";
elseif ($counter == 4)
$count = "April";
elseif ($counter == 5)
$count = "Mei";
elseif ($counter == 6)
$count = "Juni";
elseif ($counter == 7)
$count = "Juli";
elseif ($counter == 8)
$count = "Augustus";
elseif ($counter == 9)
$count = "September";
elseif ($counter == 10)
$count = "Oktober";
elseif ($counter == 11)
$count = "November";
elseif ($counter == 12)
$count = "December";
return $count;
}
if (!$HTTP_GET_VARS[id] && !$HTTP_POST_VARS[id])
{
$counter = 1;
while($counter <= 12)
{
if ($counter == 1)
$counter = "0" . $counter;
$sql = "SELECT id,titel,datum,substring(datum, 7, 4) as year FROM nieuws WHERE SUBSTRING(datum, 4, 2) = $counter order by id DESC,year DESC";
$res = mysql_query($sql);
if (mysql_num_rows($res) >= 1)
{
$year = "$row[year]";
$berichten = mysql_num_rows($res);
$month = maand($counter);
if ($berichten == 1)
echo "<b>$month $year</b> ($berichten bericht)";
else
echo "<b>$month $year</b> ($berichten berichten)";
echo "<blockquote>";
while ($row = mysql_fetch_array($res))
{
$sql2 = "select id from reacties where tid = $row[id]";
$res2 = mysql_query($sql2);
$count = mysql_num_rows($res2);
echo "[$row[datum]] <a href=$PHP_SELF?id=$row[id]>$row[titel]</a> ($count)<br>";
}
echo "</blockquote><p>";
}
else
{
if ($counter <= 12)
{
$length = strlen(maand($counter)) - 1;
$month = strtoupper(substr(maand($counter), 0, -$length)) . substr(maand($counter), 1);
if ($counter == 11)
$months .= "$month en ";
elseif ($counter == 12)
$months .= "$month";
else
$months .= "$month" . ", ";
}
if ($counter == 12)
{
if (strlen($months) <= 8)
echo "Er zijn (nog) geen nieuwsberichten van de maand: $months.";
else
echo "Er zijn (nog) geen nieuwsberichten van de maanden: $months.";
}
}
$counter++;
}
}
else
{
if ($HTTP_POST_VARS["submit"] && $HTTP_POST_VARS["naam"] && $HTTP_POST_VARS["msg"])
{
$datum = date("d.m.Y H:i");
$sql = "INSERT INTO reacties (id, naam, titel, msg, datum, ipadres, tid) VALUES ";
$sql .= "('', '$HTTP_POST_VARS[naam]', '$HTTP_POST_VARS[titel]', '$HTTP_POST_VARS[msg]', '$datum', '$REMOTE_ADDR', '$HTTP_GET_VARS[id]')";
$res = mysql_query($sql);
if ($res)
echo "<SCRIPT LANGUAGE=\"javascript\" TYPE=\"text/javascript\">window.location='$PHP_SELF?id=$HTTP_GET_VARS[id]'</SCRIPT>\n";
else
echo "Reactie niet toegevoegd.";
}
else
{
$sql = "SELECT id,titel,msg,datum FROM nieuws WHERE id = '$HTTP_GET_VARS[id]'";
$res = mysql_query($sql);
echo "<a href=\"$PHP_SELF\" target=\"_top\">Nieuws overzicht</a><p>";
if (mysql_num_rows($res) >= 1)
{
$row = mysql_fetch_array($res);
$hiddentitel = $row[titel];
echo "<span class=\"kopje\">$row[titel]</span> [$row[datum]]<p>";
$row[msg] = nl2br($row[msg]);
echo "$row[msg]<p>";
echo "<hr color=\"#000000\"><p>";
$sql = "SELECT id,naam,titel,msg,datum FROM reacties WHERE tid = '$HTTP_GET_VARS[id]' ORDER BY id DESC";
$res = mysql_query($sql);
echo "<a name=\"reacties\"><table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#CFC9B4\" width=\"100%\"><tr><td>";
echo "<table border=0 cellspacing=0 cellpadding=5 width=\"100%\"></a>";
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
echo "<tr><td bgcolor=\"#CFC9B4\"><font color=\"#000000\"><b>$row[naam]</b> [</font>$row[datum]<font color=\"#000000\">]</font></td></tr>";
$row[msg] = nl2br($row[msg]);
echo "<tr><td bgcolor=\"#E4DECA\"><font color=\"#000000\">$row[msg]</font></td></tr>";
}
}
else
{
echo "<tr><td bgcolor=\"#CFC9B4\">Er zijn nog geen reacties op dit bericht</td></tr>";
}
echo "</td></tr></table></table><p>";
echo "<form method=\"post\" action=\"$PHP_SELF?id=$HTTP_GET_VARS[id]\">";
echo "<input type=\"hidden\" name=\"titel\" value=\"$hiddentitel\">";
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" bgcolor=\"#E4DECA\" bordercolor=\"#CFC9B4\" width=\"100%\">";
echo "<tr><td><table border=0 cellspacing=0 cellpadding=0>";
echo "<tr><td width=\"60\" valign=\"top\"><font color=\"#000000\">Naam</font></td><td><input type=\"text\" name=\"naam\">";
echo "<tr><td width=\"60\" valign=\"top\"><font color=\"#000000\">Bericht</font></td><td><textarea name=\"msg\" rows=\"5\" cols=\"40\"></textarea>";
echo "<tr><td width=\"60\"> </td><td><input type=\"submit\" name=\"submit\" value=\"Reactie plaatsen\">";
echo "</table></td></tr>";
echo "</table>";
echo "</form>";
}
else
{
echo "Nieuws bericht niet gevonden.";
}
echo "<p><a href=\"$PHP_SELF\" target=\"_top\">Nieuws overzicht</a><p>";
}
}
?>
function maand($counter)
{
if ($counter == 1)
$count = "Januari";
elseif ($counter == 2)
$count = "Februari";
elseif ($counter == 3)
$count = "Maart";
elseif ($counter == 4)
$count = "April";
elseif ($counter == 5)
$count = "Mei";
elseif ($counter == 6)
$count = "Juni";
elseif ($counter == 7)
$count = "Juli";
elseif ($counter == 8)
$count = "Augustus";
elseif ($counter == 9)
$count = "September";
elseif ($counter == 10)
$count = "Oktober";
elseif ($counter == 11)
$count = "November";
elseif ($counter == 12)
$count = "December";
return $count;
}
if (!$HTTP_GET_VARS[id] && !$HTTP_POST_VARS[id])
{
$counter = 1;
while($counter <= 12)
{
if ($counter == 1)
$counter = "0" . $counter;
$sql = "SELECT id,titel,datum,substring(datum, 7, 4) as year FROM nieuws WHERE SUBSTRING(datum, 4, 2) = $counter order by id DESC,year DESC";
$res = mysql_query($sql);
if (mysql_num_rows($res) >= 1)
{
$year = "$row[year]";
$berichten = mysql_num_rows($res);
$month = maand($counter);
if ($berichten == 1)
echo "<b>$month $year</b> ($berichten bericht)";
else
echo "<b>$month $year</b> ($berichten berichten)";
echo "<blockquote>";
while ($row = mysql_fetch_array($res))
{
$sql2 = "select id from reacties where tid = $row[id]";
$res2 = mysql_query($sql2);
$count = mysql_num_rows($res2);
echo "[$row[datum]] <a href=$PHP_SELF?id=$row[id]>$row[titel]</a> ($count)<br>";
}
echo "</blockquote><p>";
}
else
{
if ($counter <= 12)
{
$length = strlen(maand($counter)) - 1;
$month = strtoupper(substr(maand($counter), 0, -$length)) . substr(maand($counter), 1);
if ($counter == 11)
$months .= "$month en ";
elseif ($counter == 12)
$months .= "$month";
else
$months .= "$month" . ", ";
}
if ($counter == 12)
{
if (strlen($months) <= 8)
echo "Er zijn (nog) geen nieuwsberichten van de maand: $months.";
else
echo "Er zijn (nog) geen nieuwsberichten van de maanden: $months.";
}
}
$counter++;
}
}
else
{
if ($HTTP_POST_VARS["submit"] && $HTTP_POST_VARS["naam"] && $HTTP_POST_VARS["msg"])
{
$datum = date("d.m.Y H:i");
$sql = "INSERT INTO reacties (id, naam, titel, msg, datum, ipadres, tid) VALUES ";
$sql .= "('', '$HTTP_POST_VARS[naam]', '$HTTP_POST_VARS[titel]', '$HTTP_POST_VARS[msg]', '$datum', '$REMOTE_ADDR', '$HTTP_GET_VARS[id]')";
$res = mysql_query($sql);
if ($res)
echo "<SCRIPT LANGUAGE=\"javascript\" TYPE=\"text/javascript\">window.location='$PHP_SELF?id=$HTTP_GET_VARS[id]'</SCRIPT>\n";
else
echo "Reactie niet toegevoegd.";
}
else
{
$sql = "SELECT id,titel,msg,datum FROM nieuws WHERE id = '$HTTP_GET_VARS[id]'";
$res = mysql_query($sql);
echo "<a href=\"$PHP_SELF\" target=\"_top\">Nieuws overzicht</a><p>";
if (mysql_num_rows($res) >= 1)
{
$row = mysql_fetch_array($res);
$hiddentitel = $row[titel];
echo "<span class=\"kopje\">$row[titel]</span> [$row[datum]]<p>";
$row[msg] = nl2br($row[msg]);
echo "$row[msg]<p>";
echo "<hr color=\"#000000\"><p>";
$sql = "SELECT id,naam,titel,msg,datum FROM reacties WHERE tid = '$HTTP_GET_VARS[id]' ORDER BY id DESC";
$res = mysql_query($sql);
echo "<a name=\"reacties\"><table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#CFC9B4\" width=\"100%\"><tr><td>";
echo "<table border=0 cellspacing=0 cellpadding=5 width=\"100%\"></a>";
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
echo "<tr><td bgcolor=\"#CFC9B4\"><font color=\"#000000\"><b>$row[naam]</b> [</font>$row[datum]<font color=\"#000000\">]</font></td></tr>";
$row[msg] = nl2br($row[msg]);
echo "<tr><td bgcolor=\"#E4DECA\"><font color=\"#000000\">$row[msg]</font></td></tr>";
}
}
else
{
echo "<tr><td bgcolor=\"#CFC9B4\">Er zijn nog geen reacties op dit bericht</td></tr>";
}
echo "</td></tr></table></table><p>";
echo "<form method=\"post\" action=\"$PHP_SELF?id=$HTTP_GET_VARS[id]\">";
echo "<input type=\"hidden\" name=\"titel\" value=\"$hiddentitel\">";
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" bgcolor=\"#E4DECA\" bordercolor=\"#CFC9B4\" width=\"100%\">";
echo "<tr><td><table border=0 cellspacing=0 cellpadding=0>";
echo "<tr><td width=\"60\" valign=\"top\"><font color=\"#000000\">Naam</font></td><td><input type=\"text\" name=\"naam\">";
echo "<tr><td width=\"60\" valign=\"top\"><font color=\"#000000\">Bericht</font></td><td><textarea name=\"msg\" rows=\"5\" cols=\"40\"></textarea>";
echo "<tr><td width=\"60\"> </td><td><input type=\"submit\" name=\"submit\" value=\"Reactie plaatsen\">";
echo "</table></td></tr>";
echo "</table>";
echo "</form>";
}
else
{
echo "Nieuws bericht niet gevonden.";
}
echo "<p><a href=\"$PHP_SELF\" target=\"_top\">Nieuws overzicht</a><p>";
}
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Joop Steur
Iemand enig idee?
Code (php)
1
2
3
2
3
<?php
$sql = "SELECT id,titel,datum,substring(datum, 7, 4) as year FROM nieuws WHERE SUBSTRING(datum, 4, 2) = $counter order by SUBSTRING(datum, 4, 2) = $counter DESC, id DESC,year DESC";
?>
$sql = "SELECT id,titel,datum,substring(datum, 7, 4) as year FROM nieuws WHERE SUBSTRING(datum, 4, 2) = $counter order by SUBSTRING(datum, 4, 2) = $counter DESC, id DESC,year DESC";
?>
ik weet niet of het werkt
Schrijf dan één zonder maanden.
Dus ipv
$var = 0;
while($var<12){ $var++ }
moet je
$var = 12;
while($var>0){ $var-- }
En iets als dit
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
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
<?php
function maand($counter)
{
if ($counter == 1)
$count = "Januari";
elseif ($counter == 2)
$count = "Februari";
elseif ($counter == 3)
$count = "Maart";
elseif ($counter == 4)
$count = "April";
elseif ($counter == 5)
$count = "Mei";
elseif ($counter == 6)
$count = "Juni";
elseif ($counter == 7)
$count = "Juli";
elseif ($counter == 8)
$count = "Augustus";
elseif ($counter == 9)
$count = "September";
elseif ($counter == 10)
$count = "Oktober";
elseif ($counter == 11)
$count = "November";
elseif ($counter == 12)
$count = "December";
return $count;
}
?>
function maand($counter)
{
if ($counter == 1)
$count = "Januari";
elseif ($counter == 2)
$count = "Februari";
elseif ($counter == 3)
$count = "Maart";
elseif ($counter == 4)
$count = "April";
elseif ($counter == 5)
$count = "Mei";
elseif ($counter == 6)
$count = "Juni";
elseif ($counter == 7)
$count = "Juli";
elseif ($counter == 8)
$count = "Augustus";
elseif ($counter == 9)
$count = "September";
elseif ($counter == 10)
$count = "Oktober";
elseif ($counter == 11)
$count = "November";
elseif ($counter == 12)
$count = "December";
return $count;
}
?>
kan veel eenvoudiger:
Code (php)
Edit:
Kleine aanpassing; ik zag dat je array met 1 moest beginnen
Kleine aanpassing; ik zag dat je array met 1 moest beginnen
Gewijzigd op 01/01/1970 01:00:00 door Jan Koehoorn