Jump to content

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


Xyphon

Recommended Posts

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

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

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

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

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

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

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.