Heb hulp nodig met pagination van mijn forum
Dus ik heb problemen met de pagination van mijn forum zoals ik al zei in de titel maar dus nu een beetje meer info, Dus hij geeft de error unexpected T_string in lijn nummer 48 ofzo ik heb er ">>>" ervoor gezet.
De 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
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
<?php
session_start(); // Start your sessions to allow your page to interact with session variables
include_once("header.php");
include_once("sidebar.php");
// Connect to the database
include_once("connect.php");
>>>if (isset($_GET[page])) { $page = $_GET[page]; } else { $page=1; };
$start_from = ($page-1) * 20;
// Function that will count how many replies each topic has
function topic_replies($cid, $tid) {
$sql = "SELECT count(*) AS topic_replies FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['topic_replies'] - 1;
}
// Function that will convert a user id into their username
function getusername($uid) {
$sql = "SELECT username FROM users WHERE id='".$uid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['username'];
}
// Function that will convert the datetime string from the database into a user-friendly format
function convertdate($date) {
$date = strtotime($date);
return date("M j, Y g:ia", $date);
}
// Assign local variables
$cid = $_GET['cid'];
// Check to see if the person accessing this page is logged in
if (isset($_SESSION['uid'])) {
$logged = " | <a href='create_topic.php?cid=".$cid."'>Klik hier om een nieuwe topic aan te maken</a><br/>";
} else {
$logged = " | Je moet inloggen/registreren om een topic te maken.";
}
function hot($views) {
if ($views > "100"){
return "<img src='img/hot_topic.png' style='height:50px;width:50px;' />";
} elseif ($views < "100") {
return "<img src='img/normal_topic.png' style='height:50px;width:50px;' />";
}
}
// Query that checks to see if the category specified in the $cid variable actually exists in the database
$sql = "SELECT id FROM categories WHERE id='".$cid."' ASC LIMIT $start_from, 20";
// Execute the SELECT query
$res = mysql_query($sql) or die(mysql_error());
// Check if the category exists
if (mysql_num_rows($res) == 1) {
// Select the topics that are associated with this category id and order by the topic_reply_date
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
// Execute the SELECT query
$res2 = mysql_query($sql2) or die(mysql_error());
// Check to see if there are topics in the category
if (mysql_num_rows($res2) > 0) {
// Appending table data to the $topics variable for output on the page
$table .= "<a href='index.php'>Return To Forum Index</a>".$logged."<br />";
$table .= "<table class='bordered'>";
$table .= "<tr><th width='50' align='center'></th><th>Topic Titel</th><th width='65' align='center'>Laatste gebruiker</th><th width='65' align='center'>Antwoorden</th><th width='65' height='48px' align='center'>Bekeken</th></tr>";
// Fetching topic data from the database
while ($row = mysql_fetch_assoc($res2)) {
// Assign local variables from the database data
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
$sticky = $row['type'];
// Check om te zien of iemand ooit al een reply gedaan heeft
if ($row['topic_last_user'] == "") { $last_user = "N/A"; } else { $last_user = getusername($row['topic_last_user']); }
// Append the actual topic data to the $topics variable
$topics .= "<tr><td>".hot($row['topic_views'])."<td><a href='view_topic.php?cid=".$cid."&tid=".$tid."'>".$title."</a><br /><span class='post_info'>Posted by: ".getusername($creator)." on ".convertdate($date)."</span></td><td align='center' style=''>".$last_user."</td><td align='center' style=''>".topic_replies($cid, $tid)."</td><td align='center' style=''>".$views."</td></tr>";
$sticky_topics .= "<tr><td><img src='img/sticky.png' style='height:50px;width:50px;' /><td><a href='rules.php'>Regels</a><br /><span class='post_info'>Posted by: Damaru2 on Jun 2, 2013 12:33pm</span></td><td align='center' style=''>Damaru2</td><td align='center' style=''>-1</td><td align='center' style=''>-1</td></tr>";
}
$topics .= "</table>";
// Displaying the $topics variable on the page
echo $table;
echo $sticky_topics;
echo $topics;
$sql = "SELECT id FROM categories WHERE id='".$cid."'";
$rs_result = mysql_query($sql2) or die(mysql_error());
$row = mysql_fetch_row($rs_result);
$total_records = count($row);
$total_pages = ceil($total_records / 20);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
};
} else {
// If there are no topics
echo "<a href='index.php'>Return To Forum Index</a>";
echo "<p>There are no topics in this category yet.".$logged."</p>";
}
} else {
// If the category does not exist
echo "<a href='index.php'>Return To Forum Index</a>";
echo "<p>You are trying to view a category that does not exist yet.</p>";
}
echo "<br /><img src='img/hot_topic.png' style='height:20px;width:20px;' /> = Vaakbezochte Topic
<img src='img/normal_topic.png' style='height:20px;width:20px;' /> = Normale Topic";
include_once("footer.php");
?>
session_start(); // Start your sessions to allow your page to interact with session variables
include_once("header.php");
include_once("sidebar.php");
// Connect to the database
include_once("connect.php");
>>>if (isset($_GET[page])) { $page = $_GET[page]; } else { $page=1; };
$start_from = ($page-1) * 20;
// Function that will count how many replies each topic has
function topic_replies($cid, $tid) {
$sql = "SELECT count(*) AS topic_replies FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['topic_replies'] - 1;
}
// Function that will convert a user id into their username
function getusername($uid) {
$sql = "SELECT username FROM users WHERE id='".$uid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['username'];
}
// Function that will convert the datetime string from the database into a user-friendly format
function convertdate($date) {
$date = strtotime($date);
return date("M j, Y g:ia", $date);
}
// Assign local variables
$cid = $_GET['cid'];
// Check to see if the person accessing this page is logged in
if (isset($_SESSION['uid'])) {
$logged = " | <a href='create_topic.php?cid=".$cid."'>Klik hier om een nieuwe topic aan te maken</a><br/>";
} else {
$logged = " | Je moet inloggen/registreren om een topic te maken.";
}
function hot($views) {
if ($views > "100"){
return "<img src='img/hot_topic.png' style='height:50px;width:50px;' />";
} elseif ($views < "100") {
return "<img src='img/normal_topic.png' style='height:50px;width:50px;' />";
}
}
// Query that checks to see if the category specified in the $cid variable actually exists in the database
$sql = "SELECT id FROM categories WHERE id='".$cid."' ASC LIMIT $start_from, 20";
// Execute the SELECT query
$res = mysql_query($sql) or die(mysql_error());
// Check if the category exists
if (mysql_num_rows($res) == 1) {
// Select the topics that are associated with this category id and order by the topic_reply_date
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
// Execute the SELECT query
$res2 = mysql_query($sql2) or die(mysql_error());
// Check to see if there are topics in the category
if (mysql_num_rows($res2) > 0) {
// Appending table data to the $topics variable for output on the page
$table .= "<a href='index.php'>Return To Forum Index</a>".$logged."<br />";
$table .= "<table class='bordered'>";
$table .= "<tr><th width='50' align='center'></th><th>Topic Titel</th><th width='65' align='center'>Laatste gebruiker</th><th width='65' align='center'>Antwoorden</th><th width='65' height='48px' align='center'>Bekeken</th></tr>";
// Fetching topic data from the database
while ($row = mysql_fetch_assoc($res2)) {
// Assign local variables from the database data
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
$sticky = $row['type'];
// Check om te zien of iemand ooit al een reply gedaan heeft
if ($row['topic_last_user'] == "") { $last_user = "N/A"; } else { $last_user = getusername($row['topic_last_user']); }
// Append the actual topic data to the $topics variable
$topics .= "<tr><td>".hot($row['topic_views'])."<td><a href='view_topic.php?cid=".$cid."&tid=".$tid."'>".$title."</a><br /><span class='post_info'>Posted by: ".getusername($creator)." on ".convertdate($date)."</span></td><td align='center' style=''>".$last_user."</td><td align='center' style=''>".topic_replies($cid, $tid)."</td><td align='center' style=''>".$views."</td></tr>";
$sticky_topics .= "<tr><td><img src='img/sticky.png' style='height:50px;width:50px;' /><td><a href='rules.php'>Regels</a><br /><span class='post_info'>Posted by: Damaru2 on Jun 2, 2013 12:33pm</span></td><td align='center' style=''>Damaru2</td><td align='center' style=''>-1</td><td align='center' style=''>-1</td></tr>";
}
$topics .= "</table>";
// Displaying the $topics variable on the page
echo $table;
echo $sticky_topics;
echo $topics;
$sql = "SELECT id FROM categories WHERE id='".$cid."'";
$rs_result = mysql_query($sql2) or die(mysql_error());
$row = mysql_fetch_row($rs_result);
$total_records = count($row);
$total_pages = ceil($total_records / 20);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
};
} else {
// If there are no topics
echo "<a href='index.php'>Return To Forum Index</a>";
echo "<p>There are no topics in this category yet.".$logged."</p>";
}
} else {
// If the category does not exist
echo "<a href='index.php'>Return To Forum Index</a>";
echo "<p>You are trying to view a category that does not exist yet.</p>";
}
echo "<br /><img src='img/hot_topic.png' style='height:20px;width:20px;' /> = Vaakbezochte Topic
<img src='img/normal_topic.png' style='height:20px;width:20px;' /> = Normale Topic";
include_once("footer.php");
?>
Groetjes Jasper
Gewijzigd op 02/06/2013 19:36:29 door Jasper De Moor
$_GET[page]; -> $_GET['page'];
maarja tnx ;)
Tekst moet in PHP altijd tussen quotes