Some thoughts;
I'm not sure about the way you're using $results['post_id'] (note the quotes!) as the index for the $postinfo array. If think you'd be better off letting $postinfo define it's own index.
Also what are you trying to do here;
PHP Code:
$postinfo[$results[post_id]]-> displayTime();
$postinfo[$results[post_id]]-> displayDate();
$postinfo[$results[post_id]]-> displayAuthor();
$postinfo[$results[post_id]]-> displayContent();
?
Here's how I'd do what you're doing (using procedural code);
PHP Code:
// Does this query really need to be so complex?
$sql = "SELECT
post_date, post_title, category_name, user_name
FROM
$tableposts
INNER JOIN
$tablecategory
ON
$tableposts.post_category = $tablecategory.category_id
INNER JOIN
$tableusers
ON
$tableposts.post_userid = $tableusers.user_id
LIMIT 5";
$results = $db_sql->query($sql);
$postinfo=array(); // Initialize
// Note "$result =" NOT "$results = "
while($result = $db_sql->fetchArray($results)) {
$postinfo[] = new News($result);
}
// Output here
foreach ( $postinfo as $post ) {
echo ( 'Posted at '.$post->time() );
}
Have a read of this and this for some more ideas.
Bookmarks