Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 5 of 5
  1. #1
    lucien is queen Hazzystan's Avatar

    Join Date
    Feb 2008
    Location
    Scotland
    Posts
    2,977

    PHP Comment board

    I'm trying to make a comment board, where the newest comments are at the top, and the oldest are at the bottom. I've got something, but it doesn't seem to reverse the data from the database.

    Could anyone point me in the right direction? Here's what I've got so far.

    Code:
    $sql = "select * from table";
           $result = mysql_query ($sql);
    
    while ($row = mysql_fetch_array($result))
                  {
                    $reverse = array_reverse($row);
                  	
                $name = $reverse["name"];
                $email = $reverse["email"];
                $comment = $reverse["comment"];
       
                echo $name . '
    ';
                echo $email; . '
    ';
                echo $comment;
                }
    what is homo love?

  2. #2
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: PHP Comment board

    The way you're doing it is illogical.

    You can order data simply via the sql statment itself without any extra code.

    ORDER BY DESC

    OR ASC

    http://www.w3schools.com/PHP/php_mysql_order_by.asp

    If you have auto increment field, you can order by it to get the results you desire.

  3. #3
    lucien is queen Hazzystan's Avatar

    Join Date
    Feb 2008
    Location
    Scotland
    Posts
    2,977

    Re: PHP Comment board

    Quote Originally Posted by Adam
    The way you're doing it is illogical.

    You can order data simply via the sql statment itself without any extra code.

    ORDER BY DESC

    OR ASC

    http://www.w3schools.com/PHP/php_mysql_order_by.asp

    If you have auto increment field, you can order by it to get the results you desire.
    Oh, I though the ORDER BY statement only applied to numbers, but I think it works. Thanks



    E-

    I've created a php code which counts up the number of records in the database, adds 1 to that number, and stores it in a column called count when a comment is posted. It should give the newest comment the highest number, and vice versa. Here it is:

    Code:
    $count = mysql_query("SELECT COUNT(*) FROM table");
    $countresult = $count+1;
    
    mysql_query("INSERT INTO table (count) VALUES ('$countresult') ")
    or die(mysql_error());
    And on the comment board, I used the ORDER BY statement to try to reverse the count, thus reversing the comments:

    Code:
    $sql = "select * from table ORDER BY count DESC";
           $result = mysql_query ($sql);
    But the number doesn't get automatically assigned, I have to manually go to php-myadmin to do it :\
    Simply inserting ORDER BY DESC Doesn't work at all, it seems that it only works with integers.
    what is homo love?

  4. #4
    Veteran Enthusiast

    Join Date
    Jul 2006
    Location
    106 is fumpin', pumpin' up in this hoe, for sho, my bro
    Posts
    7,112

    Re: PHP Comment board

    Just create an auto increment column in the table like Adam mentioned.
    [center:3mdlh4lx]Fuck you. Cunt.[/center:3mdlh4lx]

  5. #5
    lucien is queen Hazzystan's Avatar

    Join Date
    Feb 2008
    Location
    Scotland
    Posts
    2,977

    Re: PHP Comment board

    Shit, yeah, I'm an idiot. Feel free to lock.
    what is homo love?


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •