Nieuwssyteem
Pagina: « vorige 1 2 3 4 5 volgende »
Ja, op de headlines-pagina waar je het overzicht van alle nieuws-items uit je database ophaalt, gebruik je natuurlijk geen GET.
ow, maar hoe komt de id dan in de url te staan?
GET gebruik je alleen voor individuele items.
oke, maar hoe komt het dan in de url?
Typen, en haal de nodige items uit de database of uit je $_GET.
Huh wat bedoel je?
Gewijzigd op 27/11/2011 19:25:16 door - Ariën -
Gewijzigd op 27/11/2011 19:30:29 door Marc -
mysql_query, while-loop, mysql_fetch_assoc() does the trick
Gewijzigd op 27/11/2011 19:34:21 door - Ariën -
Oke dat snap ik niet
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
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
$per_page = 6;
$pages_query = mysql_query("SELECT COUNT(`id`) FROM `news`");
$pages = ceil(mysql_result ($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page -1) * $per_page;
$getnews = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT $start, $per_page") or die (mysql_error());
while ($row = mysql_fetch_assoc($getnews))
{
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date</p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"img\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\"><a href=\"post.php?id='".$id."'\"> style=\"color:#0276D4;text-decoration:none;\">$title</a></h2>
<p class=\"texcontentp\">
$body</p>
<p class=\"leesverder\"><a href=\"post.php?id='".$id."'\">lees verder >></a>
</p>
</div>
</div>
</div>";
}
if ($pages >= 1 && $page<= $pages) {
for ($x=1; $x<=$pages; $x++) {
echo ($x == $page) ? '<a class="strong_pagination" href="?page='.$x.'">'.$x.'</a> ' : '<a class="normal_pagination" href="?page='.$x.'">'. $x.'</a> ';
}
}
EN POST.PHP
$getnews = mysql_query("SELECT * FROM news WHERE id = '".$_GET['id']."'") or die (mysql_error());
while ($row = mysql_fetch_assoc($getnews))
{
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date </p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"img\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\">$title</h2>
<p class=\"texcontentp\">
$body</p>
</div>
</div>
</div>";
}
$pages_query = mysql_query("SELECT COUNT(`id`) FROM `news`");
$pages = ceil(mysql_result ($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page -1) * $per_page;
$getnews = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT $start, $per_page") or die (mysql_error());
while ($row = mysql_fetch_assoc($getnews))
{
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date</p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"img\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\"><a href=\"post.php?id='".$id."'\"> style=\"color:#0276D4;text-decoration:none;\">$title</a></h2>
<p class=\"texcontentp\">
$body</p>
<p class=\"leesverder\"><a href=\"post.php?id='".$id."'\">lees verder >></a>
</p>
</div>
</div>
</div>";
}
if ($pages >= 1 && $page<= $pages) {
for ($x=1; $x<=$pages; $x++) {
echo ($x == $page) ? '<a class="strong_pagination" href="?page='.$x.'">'.$x.'</a> ' : '<a class="normal_pagination" href="?page='.$x.'">'. $x.'</a> ';
}
}
EN POST.PHP
$getnews = mysql_query("SELECT * FROM news WHERE id = '".$_GET['id']."'") or die (mysql_error());
while ($row = mysql_fetch_assoc($getnews))
{
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date </p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"img\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\">$title</h2>
<p class=\"texcontentp\">
$body</p>
</div>
</div>
</div>";
}
Toevoeging op 27/11/2011 20:27:26:
edit
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
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
$getnews = mysql_query("SELECT * FROM news WHERE id = '".$_GET['id']."'") or die (mysql_error());
$row = mysql_fetch_assoc($getnews);
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date | jailbreak4u</p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"IOS5_jailbreak\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\">$title</h2>
<p class=\"texcontentp\">
$body</p>
</div>
</div>
</div>";
$row = mysql_fetch_assoc($getnews);
// get data
$id = $row['id'];
$title = $row['title'];
$body = $row['body'];
$date = $row['date'];
$image = $row['image'];
$alt = $row['alt'];
$height = $row['height'];
$width = $row['width'];
echo "
<div class=\"post\">
<div class=\"postmetal\">
<p class=\"postmetalp\">geplaats op: $date | jailbreak4u</p>
</div>
<div class=\"postcontent\">
<div class=\"imagecontent\">
<img class=\"IOS5_jailbreak\" src=\"$image\" alt=\"$alt\" width=\"$width\" height=\"$height\">
</div>
<div class=\"textcontent\">
<h2 class=\"texcontenth\">$title</h2>
<p class=\"texcontentp\">
$body</p>
</div>
</div>
</div>";
Gewijzigd op 27/11/2011 20:29:32 door Marc -
Het selecten gaat niet goed
Da's jammer....
haha maar even, het lukt gewoon niet
Maar je begrijpt dat we met deze informatie weinig kunnen?
Wat tips:
- Je bent hackbaar, waar is mysql_real_escape_string() ?
- Lijn 5 t/m 13 is onzin. Waarom kopieer je variabelen?
Gewijzigd op 28/11/2011 20:46:40 door - Ariën -
nee maar kan je geen voorbeeld geven, hoe jij het zou doen
ja maar hoezo heb je een while loop nodig? ik haal het toch uit de rij waar id = id ?
Ik zou wel foutafhandeling in bouwen.
Gewijzigd op 28/11/2011 20:49:42 door - Ariën -