Code: Select all
$sql =
"SELECT id,name,message,userid,title,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated " .
"FROM news ORDER BY postdate DESC";
}
$results = $this->_dCon->doQueryResult($sql);
foreach ($results as $result) {
echo '<div id="news">';
echo '<p class="header">'. $result['title'] .' - by <a href="#">'. $result['name'] .'</a></p>';
echo $result['message'];
echo '<p class="footer">'. $result['dated'] .' - <a href="#"> Comments (10)</a></p>';
echo '</div>';
}Code: Select all
$sql = "SELECT id,name,news_id,message,userid,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated FROM news_comments WHERE news_id=$id ORDER BY postdate DESC";
$results = $this->_dCon->doQueryResult($sql);
foreach ($results as $result) {
echo '<div id="comments">';
echo '<p><a href="#">'. $result['name'] .'</a> says:</p>';
echo $result['message'];
echo '<p class="commentftr">'. $result['dated'] .'</p>';
echo '</div>';
}However, when the id is anything other than 1, it doesn't work:
[url="http://codecrypt.org/index.php?action=show&id=2"]http://codecrypt.org/index.php?action=show&id=2[/url]
There is obviously a problem with the array but I can't work it out. Here is the code for the "doQueryResult" function:
Code: Select all
function doQueryResult($sql) {
$this-> _dItems = "";
if ($sql != "") {
$this-> _dResult = mysql_query($sql, $this-> _dConnection);
$dItem = array();
while ($dItem = mysql_fetch_array($this-> _dResult)) {
$this-> _dItems[] = $dItem;
}
return $this-> _dItems;
mysql_free_result($this-> _dResult);
}
else {
return mysql_error();
}
}

