Jump to content

The MySQL help froum is inactive, so can I post this here?


Recommended Posts

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

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.

 

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

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;

<?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.

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');
?>

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');
?>

 

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");

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?

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.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.