Hello,
Please assist me to fix this calling function within printf();
I really appreciate,
Thank you in advance,
Best regards,
Please assist me to fix this calling function within printf();
I really appreciate,
Thank you in advance,
Best regards,
Code:
public function main()
{
// SQL to display the article part with number of comments and last date time of comments
$sql = "SELECT a.ID,a.title,a.content,a.timestamp,u.username, c.total_comment, c.lastcommentdate FROM article AS a LEFT JOIN user AS u on a.userID = u.ID
LEFT JOIN(SELECT articleID, COUNT(ID) as total_comment, MAX(timestamp) as lastcommentdate FROM comment GROUP by articleID)
AS c on a.ID = c.articleID ORDER BY a.ID DESC LIMIT 5";
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
printf("<hr><h3><a href=\"article()?id=%d\">%s</a></h3><b>Author %s, date %s</b><p>**%s**</p><b>%s</b> Comments and the last comment posted on %s<br> ",$row['ID'],
$row['title'], $row['username'],$row['timestamp'], substr($row['content'],0,100),$row['total_comment'], $row['lastcommentdate']);
}
}
public function article()
{
$id=0;
// to get a ID number that come from the chosen article
if(isset($_REQUEST['id'])) {
$id = intval($_REQUEST['id']);
}
// to display the comments related to the chosen article
$sql = 'SELECT a.ID, c.content,c.timestamp, u.username as comment_author FROM article AS a INNER JOIN comment AS c ON a.ID = c.articleID INNER JOIN user as u ON u.ID = c.userID WHERE a.ID = "' . $id . '" ORDER BY c.timestamp DESC LIMIT 5';
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
printf("<hr><p>%s</p><b>Author %s, Date %s</b><br><br>",$row['content'],$row['comment_author'], $row['timestamp']);
}
}