I have a function loadContent() that when called, queries a database, formats the data and should return the result. This is being used to build a very primitive CMS and this function is used to load the articles from the database.
Here is the function is question:
$articles = mysql_query("SELECT `id`, `name`, `content`, `keywords`, `description`, `access_level` FROM `tb_articles` WHERE `page_id`='$pageID'");
if(!$articles){
die('Error!: ' . mysql_error());
}
while($arts = mysql_fetch_assoc($articles)){
$content .= '<div class="article" id="art-' . $arts['id'] . '">';
$content .= '<h1>' . $arts['name'] . '</h1>';
$content .= $arts['content'];
$content .= '</div>';
}
return $content;
}else{
My problem is that nothing is being returned. The SQL is verified, it should return two rows. I have commented out everything in the loop and added the line $content .= 'test'; and changed the return statement to echo $content; and the function successfully echo'ed "test" twice. So whats wrong with what I have done?
Thanks for helping me out, I'm pretty new to PHP.
UPDATE:
The post now represents all valid changes.
I got somewhere with var_dump. I dumped $content just before the return statement. All of the articles in the database (2 of them) were displayed inside of string(2445) "". This confirms there are no problems with the query. I am now thinking it has something to do with the return statement.
$content =to$content .=at the first row in your loop.mysql_error?