Far Cry Posted June 21, 2010 Share Posted June 21, 2010 <?php include_once 'connection.php'; $query = "Select * FROM news WHERE Page = 1"; $result = mysql_query($query); while($post = mysql_fetch_array($result)) { echo "<h1>" . $row['Post_Title'] . "</h1><br>"; echo "<h3>" . $row['Post_Author'] . "</h3><br>"; echo "<p>" . $row['Post_Content'] . "</p>"; } ?> Here is the code from the index file, however when I load this page in my browser in comes out blank, when it is supposed to echo the data from my database. Can anyone help? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 You're getting the rows into the $post array, yet you're trying to display from the $row array. Ken Quote Link to comment Share on other sites More sharing options...
Far Cry Posted June 21, 2010 Author Share Posted June 21, 2010 So how do I fix the code exactly? Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 21, 2010 Share Posted June 21, 2010 Take a look in your error log. Could be any number of things related to your database connection. We don't have enough information but I would make the general comment that your code doesn't check for errors. For example, you do a mysq_query() and store the result to $result, but don't check to see if $result if valid before you try and fetch. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 Change <?php while($post = mysql_fetch_array($result)) { echo "<h1>" . $row['Post_Title'] . "</h1><br>"; echo "<h3>" . $row['Post_Author'] . "</h3><br>"; echo "<p>" . $row['Post_Content'] . "</p>"; } ?> to <?php while($row = mysql_fetch_array($result)) { echo "<h1>" . $row['Post_Title'] . "</h1><br>"; echo "<h3>" . $row['Post_Author'] . "</h3><br>"; echo "<p>" . $row['Post_Content'] . "</p>"; } ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.