Ok, so I’m trying to make some simple code to display news articles from a MySQL server but all I get is a completely blank middle part of the page where the news articles are supposed to be. Here is the code:
<?
$query = "SELECT ID, header, content FROM news ORDER BY ID DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "<div class=\"newsItem\">";
echo "<h2>" . $row['header'] . "</h2>";
echo "<p>" . $row['content'] . "</p>";
echo "</div>";
}
?>
The problem seems to be with the while loop. If I write echo “WTF”; outside the loop it will show but if i write it inside it wont show. I’m not really good at PHP so I’m puzzled. ID is INT and Primary Key, header is VARCHAR(255) and content is TEXT. Any Ideas? Also the connect scrips works cuz I dont get error messages when it dies.
Try adding an error catch:
OR you have no results. so add somthing for that: