Xyphon Posted December 15, 2007 Share Posted December 15, 2007 <?PHP include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments"); echo "<table border='1'> <tr> <th>Hi,<br /> It's Xyphon. I have just made the news page, I hope you like it! Please, leave comments here!</th> </tr></table>"; echo "<table border='1' width='500'>"; echo "<tr> <td> <a href='postcomment.php'>Post Comment</a></td>"; echo "<td> <a href='viewcomments.php'>View Comments</a></td></tr></table>"; if(!$row = mysql_fetch_array($result)){ echo "There are no current comments. Layout issues may accure."; } else { echo "<table border='1' width='500' height='20'>"; echo "<br /><br />"; echo "<tr>"; echo "<td><center><b>Username: </b><br />" . $row['username'] . "</center></td>"; echo "<td><center><b>ID: </b><br />" . $row['user_id'] . "</center></td></tr></table>"; echo "<table border='1' width='500' height='20'><tr><td><b>Comment:</b>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr></table>"; } include('bottom.php'); ?> For some reason it will only show the frist comment made, and they're all in the DB. Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2007 Share Posted December 15, 2007 You need to loop through your results. The basic syntax of a SELECT with more than one row should be... <?php if ($result = mysql_squery("SELECT a, b c FROM foo")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo "{$row['a']} {$row['b']} {$row['c']}<br />"; } } else { echo "No results found"; } } else { echo mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
themistral Posted December 15, 2007 Share Posted December 15, 2007 You don't appear to be looping through the records anywhere Change this if(!$row = mysql_fetch_array($result)){ echo "There are no current comments. Layout issues may accure."; } else { echo "<table border='1' width='500' height='20'>"; echo "<br /><br />"; echo "<tr>"; echo "<td><center><b>Username: </b><br />" . $row['username'] . "</center></td>"; echo "<td><center><b>ID: </b><br />" . $row['user_id'] . "</center></td></tr></table>"; echo "<table border='1' width='500' height='20'><tr><td><b>Comment:</b>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr></table>"; } to if(mysql_num_rows($result) > 0){ // your table headings here while ($row = mysql_fetch_array($result)) { // your rows with database content here } } else { echo "There are no current comments. Layout issues may accure."; } Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Can you edit the whole code and show me? It is a little confusing the way you say it. Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 ? Quote Link to comment Share on other sites More sharing options...
themistral Posted December 15, 2007 Share Posted December 15, 2007 if (mysql_num_rows($result) > 0) { echo "<table border='1' width='500' height='20'>"; echo "<br /><br />"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><center><b>Username: </b><br />" . $row['username'] . "</center></td>"; echo "<td><center><b>ID: </b><br />" . $row['user_id'] . "</center></td></tr></table>"; echo "<table border='1' width='500' height='20'><tr><td><b>Comment:</b>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr></table>"; } echo "</table>"; } else { echo "There are no current comments. Layout issues may accure."; } That will show the username for every comment but it gives you the idea of how it works I hope!! HTH! Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 No it doesnt. Can you edit my entire code and add it in, and dont change any of the form? Quote Link to comment Share on other sites More sharing options...
themistral Posted December 15, 2007 Share Posted December 15, 2007 <?PHP include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments"); echo "<table border='1'> <tr> <th>Hi,<br /> It's Xyphon. I have just made the news page, I hope you like it! Please, leave comments here!</th> </tr></table>"; echo "<table border='1' width='500'>"; echo "<tr> <td> <a href='postcomment.php'>Post Comment</a></td>"; echo "<td> <a href='viewcomments.php'>View Comments</a></td></tr></table>"; if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { echo "<table border='1' width='500' height='20'>"; echo "<br /><br />"; echo "<tr>"; echo "<td><center><b>Username: </b><br />" . $row['cty_id'] . "</center></td>"; echo "<td><center><b>ID: </b><br />" . $row['cty_name'] . "</center></td></tr></table>"; echo "<table border='1' width='500' height='20'><tr><td><b>Comment:</b></td>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr>"; echo "</table>"; } } else { echo "There are no current comments. Layout issues may accure."; } include('bottom.php'); ?> I have tried this out with my own site and this does work... 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.