Ok using similar code, I am trying to show a list of authors, and their respective written articles.
This is the code i am trying to use :
PHP Code:
$authorquery = $DB_site->query("
SELECT * FROM " . TABLE_PREFIX . "articles_article a
LEFT JOIN " . TABLE_PREFIX . "user u
ON a.author=u.username
ORDER BY a.author asc
");
$artbyauthorquery = $DB_site->query("
SELECT articles_articleid, title, author
FROM " . TABLE_PREFIX . "articles_article
ORDER BY publishdate desc
");
$author_cache = array();
while ($author = $DB_site->fetch_array($artbyauthorquery))
{
$author_cache[$author['author']][] = $author;
}
// authors
foreach ($author_cache['author'] AS $author)
{
$userid = $author["userid"];
$author = $author["author"];
// articles by the authors
foreach ($author_cache[$author] AS $article)
{
$arttitle=$article["title"];
$artid=$article["articles_articleid"];
eval('$authorartbit .= "' . fetch_template('vbArticles_authorartbit') . '";');
}
eval('$authorbit .= "' . fetch_template('vbArticles_authorbit') . '";');
}
$navbits = construct_navbits(array('' => $vbphrase['vbarticles']));
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('vbArticles_authorlist') . '");');
}
However it gives me an error at the line :
PHP Code:
foreach ($author_cache['author'] AS $author)
Something to do with the 'author' there I think. I need to put in the value there which is the name of the authors, correct ?
foreach works with strings in the array too, so how come this is not accepted ?
error is "Invalid argument supplied for foreach()".