Jump to content

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


Xyphon

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

Link to comment
Share on other sites

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

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

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

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

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

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

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

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.