[code]$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]
That code works fine. The problem I'm having is when I try to display itemes which are called by their id:
[code]$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>';
}[/code]
Now this works fine when the id is 1: [url=\"http://codecrypt.org/index.php?action=show&id=1\"]http://codecrypt.org/index.php?action=show&id=1[/url]
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]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();
}
}[/code]
As you can see it puts the sql into an array. Maybe I need to change the function or add a new one that grabs just one item and doesn't put it in an array, but I think there is another way to solve this. Thanks in advance


