PHP Date/Time question

Discussion in 'OT Technology' started by FloppyCock, Jul 13, 2006.

  1. FloppyCock

    FloppyCock New Member

    Joined:
    Jan 15, 2001
    Messages:
    5,630
    Likes Received:
    0
    Location:
    California
    I am having trouble sorting entries by when they were created. I am currently using <?php echo date('Y-m-d H:m:s'); ?> to timestamp entries, but when I go to order them by date, the time is ignored. Entries from the same date are not sorted by time, nor is time displayed when I output the date.

    Any ideas/suggestions?
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    is this from a MySQL recordset? If so, why not use the "ORDER BY" directive?

    Otherwise, how is the data stored? array? linked-list? b-tree?
     
  3. FloppyCock

    FloppyCock New Member

    Joined:
    Jan 15, 2001
    Messages:
    5,630
    Likes Received:
    0
    Location:
    California
    It is from a MySQL recordset, and I am using the ORDER BY directive. For some reason, the ordering is only by day, not by time. The most recent entry is not necessarily the top of the list.
     
  4. Bruticus

    Bruticus half dead OT Supporter

    Joined:
    Apr 10, 2004
    Messages:
    4,608
    Likes Received:
    0
    Location:
    Melbourne
    Check if the time data is actually being saved? Your SQL tables could be incorrect.
     
  5. FloppyCock

    FloppyCock New Member

    Joined:
    Jan 15, 2001
    Messages:
    5,630
    Likes Received:
    0
    Location:
    California
    It is, just not to the resolution of the actual time. Entries are properly sorted by their calender date.

    The problem is, lets say I add two entries, one after the other. I want them to be sorted by their respective times, as well as dates. Right now, as long as entries are from the same day, their order is arbitrary.
     
    Last edited: Jul 13, 2006
  6. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    my understanding of this is the data is stored as

    YYYYMMDDHHmmSS, so order SHOULD be by year, month, day, hour, minute, second -- in that order.
     
  7. FloppyCock

    FloppyCock New Member

    Joined:
    Jan 15, 2001
    Messages:
    5,630
    Likes Received:
    0
    Location:
    California
    Could it be the way that I timestamp entries? I use <?php echo date('Y-m-d H:m:s'); ?>
     
  8. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    post the recordset, please.
     
  9. FloppyCock

    FloppyCock New Member

    Joined:
    Jan 15, 2001
    Messages:
    5,630
    Likes Received:
    0
    Location:
    California
    i did it in dreamweaver, so here is the php i think is the recordset.

    $maxRows_rsReviews = 10;
    $pageNum_rsReviews = 0;
    if (isset($HTTP_GET_VARS['pageNum_rsReviews'])) {
    $pageNum_rsReviews = $HTTP_GET_VARS['pageNum_rsReviews'];
    }
    $startRow_rsReviews = $pageNum_rsReviews * $maxRows_rsReviews;

    $colname_rsReviews = "1";
    if (isset($HTTP_GET_VARS['id_mov'])) {
    $colname_rsReviews = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['id_mov'] : addslashes($HTTP_GET_VARS['id_mov']);
    }
    mysql_select_db($database_acConn, $acConn);
    $query_rsReviews = sprintf("SELECT * FROM movie_reviews INNER JOIN users ON idrev_rev=id_usr WHERE idmov_rev = %s ORDER BY date_rev DESC", $colname_rsReviews);
    $query_limit_rsReviews = sprintf("%s LIMIT %d, %d", $query_rsReviews, $startRow_rsReviews, $maxRows_rsReviews);
    $rsReviews = mysql_query($query_limit_rsReviews, $acConn) or die(mysql_error());
    $row_rsReviews = mysql_fetch_assoc($rsReviews);

    if (isset($HTTP_GET_VARS['totalRows_rsReviews'])) {
    $totalRows_rsReviews = $HTTP_GET_VARS['totalRows_rsReviews'];
    } else {
    $all_rsReviews = mysql_query($query_rsReviews);
    $totalRows_rsReviews = mysql_num_rows($all_rsReviews);
    }
    $totalPages_rsReviews = ceil($totalRows_rsReviews/$maxRows_rsReviews)-1;


    its jumbled as shit.
     

Share This Page