Results 1 to 6 of 6

Thread: Help with accending and decending comment order.

  1. #1
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with accending and decending comment order.

    I have never had so many problems with a simple little PHP comment script in my life.
    But, maybe I'm just having a bad week.
    Heres the problem:



    And the script:

    PHP Code:
    <?php
    }
    $tbl_name2 "CENSORED";

    $sql2 "SELECT * FROM $tbl_name2 WHERE CENSORED='$id'";
    $result2 mysql_query($sql2);

    while(
    $rows mysql_fetch_array($result2)){
        
    ?>
        <div style="margin-top: 10px; margin-bottom: 10px; border: 1px solid #666; -moz-border-radius: 5px; -webkit-border-radius: 5px; padding: 5px;">
        <strong><a href="<?=$rows['a_web']?>"><?=$rows['a_name']?></a></strong>&nbsp;<small>said:</small>
        <p>
        <?=$rows['a_answer']?>
        </p>
        <small><span style="font-family: georgia; color: #666">Posted on <?=$rows['a_datetime']?></span></small>
            </div>
        <?php
    }

    $sql3 "SELECT view FROM $tbl_name WHERE id='$id'";
    $result3 mysql_query($sql3);

    $rows mysql_fetch_array($result3);
    $view $rows['view'];

    if(empty(
    $view)){
        
    $view 1;
        
    $sql4 "INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
        
    $result4 mysql_query($sql4);
    }

    $addview $view+1;
    $sql5 "update $tbl_name set view='$addview' WHERE id='$id'";
    $result5 mysql_query($sql5);

    mysql_close();
    ?>
    Any help?
    Last edited by Snookerman; 05-13-2009 at 10:21 PM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Depends on how you are storing the variable "'a_datetime'".

    If it is the unix date stamp then you can do a SORT on that field when you extract the records.

    If it is not a numeric date stamp then you need to split the field and rebuild it into YYYYMMDDHHMM and then sort on that.

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Should be a simple ORDER BY statement in the query, add something like:

    PHP Code:
    "SELECT * FROM $tbl_name2 WHERE CENSORED='$id' ORDER BY `date`, `time` ASC"

  4. #4
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    You are very helpful, Schmoopy.
    Thanks!

  5. #5
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    So I changed it to order by datetime and ID, and it works!
    These forums are great!

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Glad to hear it

    Good luck with developing the rest of your site.

Bookmarks

Posting Permissions

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