|
I think I figured it out. Here is the code that is displaying total comments as -10 when it is 0. This is causing any member without a comment to get a syntax error. Does anyone know how to fix that?
$commentpage = $_REQUEST["commentpage"];
if ($commentpage == "") $commentpage = 1;
$rs = $db->prepare("SELECT COUNT(*) FROM tblusercomment WHERE posted_id = ?");
$rs->execute($userid);
$row = $rs->fetch_array();
$totalcomments = $row[0];
$perpage = 10;
$totalpages = ceil($totalcomments / $perpage);
if ($commentpage == "all") {
$sql = "SELECT tblusercomment.*, tblmember.* FROM tblusercomment " .
"INNER JOIN tblmember ON tblusercomment.poster_id = tblmember.user_id " .
"WHERE posted_id= ? " .
"ORDER BY tblusercomment.timestamp DESC";
$first = 1;
if ($totalpages > 5) {
$last = 5;
} else {
$last = $totalpages;
}
$commentpage = 0;
} else {
if ($commentpage < 1) $commentpage = 1;
if ($commentpage > $totalpages) $commentpage = $totalpages;
if ($totalpages > 5) {
if ($commentpage == 1) {
$first = 1;
$last = 5;
} elseif ($commentpage <= 2) {
$first = 1;
$last = $commentpage + 3;
} else {
$first = $commentpage - 2;
$last = $commentpage + 2;
}
} else {
$first = $commentpage;
$last = $totalpages;
}
if ($totalpages < $last) $last = $totalpages;
$sql = "SELECT tblusercomment.*, tblmember.* FROM tblusercomment " .
"INNER JOIN tblmember ON tblusercomment.poster_id = tblmember.user_id " .
"WHERE posted_id= ? " .
"ORDER BY tblusercomment.timestamp DESC LIMIT " . ( ($commentpage - 1) * $perpage ) . ", $perpage";
}
if ($commentpage > 1) {
$data = array("page" => "<a href=/viewUserProfile.php?userId=$userid><<</a>");
$pm->addLoop("comment-pages", $data);
$data = array("page" => "<a href=/viewUserProfile.php?userId=$userid&commentpage=" . ($commentpage - 1) . "><</a>");
$pm->addLoop("comment-pages", $data);
}
for ($i = $first; $i <= $last; $i++) {
if ($i != $commentpage) {
$data = array("page" => "<a href=/viewUserProfile.php?userId=$userid&commentpage=$i> $i</a>");
} else {
$data = array("page" => $i);
}
$pm->addLoop("comment-pages", $data);
}
$firstcomment = (($commentpage - 1) * $perpage) + 1;
$lastcomment = ($commentpage * $perpage);
if ($lastcomment > $totalcomments) $lastcomment = $totalcomments;
$pm->setVariable("firstcomment", $firstcomment);
$pm->setVariable("lastcomment", $lastcomment);
$pm->setVariable("totalcomments", $totalcomments);
if ($commentpage < $totalpages) {
$data = array("page" => "<a href=/viewUserProfile.php?userId=$userid&commentpage=" . ($commentpage + 1) . ">></a>");
$pm->addLoop("comment-pages", $data);
$data = array("page" => "<a href=/viewUserProfile.php?userId=$userid&commentpage=$to talpages>>></a>");
$pm->addLoop("comment-pages", $data);
}
$rs = $db->prepare($sql);
$rs->execute($userid);
while ($row = $rs->fetch_array()) {
// TODO: This stripslash is a stupid hack
$row["comment"] = stripslashes($row["comment"]);
$row["date"] = date("m/d/Y h:i a", $row["timestamp"]);
if ($userid == $_SESSION["userinfo"]["userid"]) {
$row["comment-control"] = "<form style=\"margin: 0px; padding: 0px; display: inline;\" action=\"viewUserProfile.php\" method=\"post\">" .
"<input type=\"hidden\" name=\"userId\" value=\"$userid\">" .
"<input type=\"hidden\" name=\"commentId\" value=\"" . $row["id"] . "\">" .
"<input type=\"submit\" name=\"btn\" value=\"Delete\"></form>";
} elseif ($row["poster_id"] == $_SESSION["userinfo"]["userid"]) {
$row["comment-control"] = "<form style=\"margin: 0px; padding: 0px; display: inline;\" action=\"editComment.php\" method=\"post\">" .
"<input type=\"hidden\" name=\"commentId\" value=\"" . $row["id"] . "\">" .
"<input type=\"submit\" name=\"btn\" value=\"Edit\"></form>";
}
$pm->addLoop("usercomments", $row);
}
|