Xyphon Posted December 15, 2007 Share Posted December 15, 2007 how do you make a database go backwords. So in view comments it displays last post first? Link to comment Share on other sites More sharing options...
DyslexicDog Posted December 15, 2007 Share Posted December 15, 2007 Add the ORDER BY feature to your query. If you have the query you use to select the comments I could give you an example. Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 mysql_query("SELECT * FROM comments ORDER BY id DESC"); you can change the ORDER BY thingy but all you really need is the DESC to make it go backwards Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 how do you make a database go backwords. So in view comments it displays last post first? Like I said before, you need DATE coloumn to order the Comments by First Post, or Last Post. When you have a `date` DATETIME NOT NULL, then you can do $mysql_query("SELECT * FROM comments ORDER BY date ASC"); // DESC would be first post, and ASC would be last Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 Doesn't DESC give you the last one first? http://www.w3schools.com/php/php_mysql_order_by.asp#table8 Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 mysql_query("SELECT * FROM comments ORDER BY id DESC"); you can change the ORDER BY thingy but all you really need is the DESC to make it go backwards I put mysql_query("SELECT * FROM news_comments ORDER BY id_comment DESC"); nothing changed. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 how do you make a database go backwords. So in view comments it displays last post first? Like I said before, you need DATE coloumn to order the Comments by First Post, or Last Post. When you have a `date` DATETIME NOT NULL, then you can do $mysql_query("SELECT * FROM comments ORDER BY date ASC"); // DESC would be first post, and ASC would be last read what i said. YOU CANT ORDER BY ID Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 try ASC like phpSensei suggested Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 try ASC like phpSensei suggested It won't matter, he needs a DATE field. Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 oh, well if he has an ID column that auto increases so that each ID is unique and the newest post gets the newest ID, wont that work the same? Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 Oh wait, are you using mysql_fetch_array() or are you just using mysql_query() you need to add a while() loop with the mysql_fetch_array() function Link to comment Share on other sites More sharing options...
DyslexicDog Posted December 15, 2007 Share Posted December 15, 2007 oh, well if he has an ID column that auto increases so that each ID is unique and the newest post gets the newest ID, wont that work the same? It will work if your select statement somehow eliminates the comments that don't apply to your current view. SELECT * FROM comments WHERE post_id = $post_id ORDER BY comment_id ASC; Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Ive tried what you said. And now im very confused. 1. It says the date tihng isnt a real function 2. My dates dont go UP 3. All of the other suggesions dont work. Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 what exactly are your results? can you post your script so that I can see how you are doing it? Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 <?PHP include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments"); mysql_query("SELECT id_comment FROM news_comments ORDER BY id_comment 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'); ?> Thats my code, DESC, or ASC, no differance. Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 try this: <?php include('Connect.php'); include('top.php'); $result = mysql_query("SELECT id_comment FROM news_comments ORDER BY id_comment DESC"); 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...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 EDIT: NVM, someone already posted it. try <?PHP include('Connect.php'); include('top.php'); $result = mysql_query("SELECT id_comment FROM news_comments ORDER BY id_comment 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 Ugh, I just noticed this. It wont display the firts comment I make, no matter what I do. It displays all of the others, though. Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Thats why you shouldnt use an AUTO_INCREMENT field to ORDER BY. Make a DATE coloumn, and make it as DATE TIME, Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Lol, dude. It did the comment thing BEFORE I added that in! Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Lol, dude. It did the comment thing BEFORE I added that in! Then change $result = mysql_query("SELECT id_comment FROM news_comments ORDER BY id_comment ASC"); to $result = mysql_query("SELECT * FROM news_comments ORDER BY id_comment ASC"); Link to comment Share on other sites More sharing options...
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 Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 what is the id of your first comment? 1 or 0 if its 0 then that might be why its not showing it.... not sure though Link to comment Share on other sites More sharing options...
Xyphon Posted December 15, 2007 Author Share Posted December 15, 2007 Its 1. <?PHP include('Connect.php'); include('top.php'); $result = mysql_query("SELECT * FROM news_comments ORDER BY id_comment DESC"); 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."; } 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'); ?> Whats wrong there? Link to comment Share on other sites More sharing options...
phpSensei Posted December 15, 2007 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. Link to comment Share on other sites More sharing options...
Recommended Posts