PDA

View Full Version : Displaying Posts from a Thread


Nothematic
10-29-2014, 09:43 PM
Hi all,

I'm trying to display every post in a specified thread on an external page. I'm using this (awful) code but I'm not able to get it to display anything. Anyone got any ideas as to why? I'm not the best when it comes to PHP and MySQL. Thanks.

<?php
$username = *FORUM_DB_USERNAME*
$password = *FORUM_DB_PASSWORD*
$forumcon = new PDO('mysql:host=localhost;dbname=*FORUM_DB_NAME*', $username, $password);

$posts = "SELECT `title`, `pagetext` FROM `post` WHERE `threadid=2"; //specified threadid 2
$result = $forumcon->prepare($posts);
$result->execute();

while($row = $result-fetch()) {
echo "<b>" . htmlspecialchars($row['title']) . "</b>";
echo "<hr />";
echo htmlspecialchars($row['pagetext']);
echo "<br /><br />";
}
?>

kh99
10-30-2014, 08:29 AM
I'm not familiar with PDO so I don't know if the code is correct, but in the sql string you have a backtick at the beginning of threadid, but not at the end.