Page 1 of 1

this function throws error whenever it get called ..

Posted: Sun May 17, 2009 3:11 pm
by pawanOO7

Code: Select all

 
function showTopic($topicid, $showfull=TRUE) {
global $conn;
global $userid;
global $limit;
echo breadcrumb($topicid, "P");
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
if ($limit == "") $limit = 25;
$start = ($page - 1) * $limit;
if (isset($_SESSION['user_id'])) {
echo topicReplyBar($topicid, getForumID($topicid), "right");
}
$sql = "SELECT SQL_CALC_FOUND_ROWS ".
"p.id, p.subject, p.body, p.date_posted, " .
"p.date_updated, u.name as author, u.id as author_id, " .
"u.signature as sig, c.count as postcount, " .
"p.forum_id as forum_id, f.forum_moderator as mod, " .
"p.update_id, u2.name as updated_by " .
"FROM forum_forum f " .
"JOIN forum_posts p " .
"ON f.id = p.forum_id " .
"JOIN forum_users u " .
"ON u.id = p.author_id " .
"LEFT JOIN forum_users u2 " .
"ON u2.id = p.update_id " .
"LEFT JOIN forum_postcount c " .
"ON u.id = c.user_id " .
"WHERE (p.topic_id = $topicid OR p.id = $topicid) " .
"ORDER BY p.topic_id, p.date_posted ".
"LIMIT $start,$limit";
$result = mysql_query($sql, $conn)
or die(mysql_error() . "<br>" . $sql);
$pagelinks = paginate($limit);
if (mysql_num_rows($result) == 0) {
$msg = "There are currently no posts. Would you " .
"like to be the first person to create a thread?";
$title = "No Posts...";
$dest = "compose.php?forumid=" . $forumid;
$sev = "Info";
$message = msgBox($msg,$title,$dest,$sev);
echo $message;
} else {
echo "<table class=\"forumtable\" cellspacing=\"0\" ";
echo "cellpadding=\"2\"><tr>";
echo "<th class=\"author\">Author</th>";
echo "<th class=\"post\">Post</th>";
echo "</tr>";
$rowclass = "";
while ($row = mysql_fetch_array($result)) {
$lastupdate = "";
$editlink = "";
$dellink = "";
$replylink = "&nbsp;";
$pcount = "";
$pdate = "";
$sig = "";
if ($showfull) {
$body = $row['body'];
if (isset($_SESSION['user_id'])) {
$replylink = "<a href=\"compose.php?forumid=" .
$row['forum_id'] . "&topicid=$topicid&reid=" . $row['id'] .
"\" class=\"buttonlink\">REPLY</a>&nbsp;";
} else {
} else {
$replylink = "";
}
if ($row['update_id'] > 0) {
$lastupdate = "<p class=\"smallNote\">Last updated: " .
$row['date_updated'] . " by " .
$row['updated_by'] . "</p>";
}
if (($userid == $row['author_id']) or
($userid == $row['mod']) or
($_SESSION['access_lvl'] > 2)) {
$editlink = "<a href=\"compose.php?a=edit&post=".$row['id'].
"\" class=\"buttonlink\">EDIT</a>&nbsp;";
$dellink = "<a href=\"transact-affirm.php?action=deletepost&".
"id=" . $row['id'] .
"\" class=\"buttonlink\">DELETE</a>&nbsp;";
}
$pcount = "<br><span class=\"textsmall\">Posts: " .
($row['postcount']==""?"0":$row['postcount']) . "</span>";
$pdate = $row['date_posted'];
$sig = ($row['sig'] != ""?"<p class=\"sig\">".
bbcode(nl2br($row['sig'])):"")."</p>";
} else {
$body = trimBody($body);
}
$rowclass = ($rowclass == "row1"?"row2":"row1");
echo "<tr class=\"$rowclass\">";
echo "<td class=\"author\">" . $row['author'];
}
}
 

ERROR:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod, p.update_id, u2.name as updated_by FROM forum_forum f JOIN forum_posts p ON' at line 1
SELECT SQL_CALC_FOUND_ROWS p.id, p.subject, p.body, p.date_posted, p.date_updated, u.name as author, u.id as author_id, u.signature as sig, c.count as postcount, p.forum_id as forum_id, f.forum_moderator as mod, p.update_id, u2.name as updated_by FROM forum_forum f JOIN forum_posts p ON f.id = p.forum_id JOIN forum_users u ON u.id = p.author_id LEFT JOIN forum_users u2 ON u2.id = p.update_id LEFT JOIN forum_postcount c ON u.id = c.user_id WHERE (p.topic_id = 4 OR p.id = 4) ORDER BY p.topic_id, p.date_posted LIMIT 0,10



plzzz some one help me with this
plzzzzzzzzzzzzzzzzzzzzzz

Re: this function throws error whenever it get called ..

Posted: Sun May 17, 2009 3:32 pm
by califdon
plzzzzzzzzzzz don't post PHP code like that, without using code tags around it!
plzzzzzzzzzzz read the rules of this forum before posting.
plzzzzzzzzzzz don't use expressions like plzzzzzzzzzzz.
Thank you.

Now, your problem is that you are using a reserved word, mod as the alias for a fieldname. Mod is an arithmetic operator. Ref.: http://dev.mysql.com/doc/refman/5.1/en/ ... words.html

Re: this function throws error whenever it get called ..

Posted: Mon May 18, 2009 4:21 am
by pawanOO7
i am really sorry i was unaware about the basic rules , actually i was panic aabout the error
any ways thanks for your reply it works now . next time i'll post my problem with proper tags
:)

Re: this function throws error whenever it get called ..

Posted: Mon May 18, 2009 11:21 am
by califdon
I'm glad you have it working now. I'm also glad that you are willing to learn how to get the best out of the forum (not that I'm the best, I mean you will attract more people to help you by following the rules). Come back anytime you have a problem.