Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 That makes it ordered Like this Blah blah2 insted of Blah2 Blah I just tried it. And now with DESC, The last comment disapeared, insted of the first.. DANG You selected id_comment only, and not the whole table itself. Acutally it says SELECT * if you read up properly. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Everything works fine http://ptcrpg.awardspace.com/viewcomments.php Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Yes, it looks that way. Buut I actually have another comment posted. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Yes, it looks that way. Buut I actually have another comment posted. No one ever uses ORDER BY on a AUTO_INCREMENT coloumn, specially not on the UNIQUE KEY... Make a damn DATE coloum with the DATETIME properties. Save yourself the trouble tonight. Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 LOOK! THAT IS NOT THE PROBLEM! BEFORE I HAD THAT THERE THE SAME THING HAPPENED! Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 I am not even going to take this up with you, quit being an idiot and follow people that know better than you. Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 1. For some reason the date wont display anyways it'll say 00:00:00 2. It wouldnt let me do it from the date 3. The problem was there WELL BEFORE I created that. The id_comment had nothing to do with it. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 date("Y-m-d h:i:s"); Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Ugh. You dont understand, it was there way BEFORE I added the other stuff! Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 I am only going to say this one more time 1. Create DATE column (which you have) 2. DELETE your old comments, and make some new ones with the DATES 3. Use this script <?php include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments ORDER BY date ASC"); echo "<table border='1' bgcolor='lightgrey'> <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' bgcolor='lightgrey'>"; 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 { while($row = mysql_fetch_array($result)){ echo "<table border='1' width='500' height='20' bgcolor='lightgrey'>"; 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' bgcolor='lightgrey'><tr><td><b>Comment:</b>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr></table>"; } } include('bottom.php'); ?> Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Im only going to say this one more time. If I TOOK AWAY the ordering, I'd still have the same problem. Once comments where done it happened. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Im only going to say this one more time. If I TOOK AWAY the ordering, I'd still have the same problem. Once comments where done it happened. what does the Database tables look like for news_comments? Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 lol damn I left for like 5 minutes to eat and you guys are just about ready to kill each other! Link to comment Share on other sites More sharing options...
dbo Posted December 15, 2007 Share Posted December 15, 2007 Ordering by the ID might not be the best idea, but that's not the problem. I think the problem is here: if(!$row = mysql_fetch_array($result)){ echo "There are no current comments. Layout issues may accure."; } When you've actually got data you fetch a row, and do nothing with it (first record lost). Then you loop through your results in the while loop starting at record 2. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Ordering by the ID might not be the best idea, but that's not the problem. I think the problem is here: if(!$row = mysql_fetch_array($result)){ echo "There are no current comments. Layout issues may accure."; } When you've actually got data you fetch a row, and do nothing with it (first record lost). Then you loop through your results in the while loop starting at record 2. I changed this for him before, he said that some error occured. Link to comment Share on other sites More sharing options...
dbo Posted December 15, 2007 Share Posted December 15, 2007 I really prefer for loops. $rows = mysql_num_rows($result); if( $rows == 0 ) { //Echo error message } for( $i = 0; $i < $rows; ++$i ) { //Loop through output here } Link to comment Share on other sites More sharing options...
dbo Posted December 15, 2007 Share Posted December 15, 2007 Try this (untested). <?php include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments ORDER BY date ASC"); echo "<table border='1' bgcolor='lightgrey'> <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' bgcolor='lightgrey'>"; echo "<tr> <td> <a href='postcomment.php'>Post Comment</a></td>"; echo "<td> <a href='viewcomments.php'>View Comments</a></td></tr></table>"; $rows = mysql_num_rows($result); if( $rows == 0 ) { echo "There are no current comments. Layout issues may accure."; } for( $i = 0; $i < $rows; ++$i ) { $row = mysql_fetch_array($result)){ echo "<table border='1' width='500' height='20' bgcolor='lightgrey'>"; 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' bgcolor='lightgrey'><tr><td><b>Comment:</b>"; echo "<td>" . $row['comment'] . "</td>"; echo "</tr></table>"; } include('bottom.php'); ?> Link to comment Share on other sites More sharing options...
trq Posted December 15, 2007 Share Posted December 15, 2007 Xyphon, you need to calm yourself down and learn how to ask a question properly. You also need to find some tutorials on the basics instead of having people write your code for you which is what has pretty much been happening. Theres a few good links in my signiture, read them. Link to comment Share on other sites More sharing options...
Recommended Posts