dynamic time/date variable to sort records by

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default dynamic time/date variable to sort records by

    I posted a question on this some months ago but didn't get a good answer.

    I have a very basic personal weblog on my website using a PHP script and
    MySql db to post store and retrieve my blog entries. Currently I'm using
    date("d/m/y") to populate a date text field (updated) and I also have an
    automatic TIMESTAMP field (time). When retrieving the data, I sort by time
    desc and all is dandy.

    One problem. Whenever I need to edit the data in an already created blog
    record, this automatically changes the time field (presumably because it's
    of type TIMESTAMP). This screws up the sorting of my blogs.

    Can anyone suggest a way whereby I can store today's date in a format that
    is sortable in descending order, allowing me to display records as I wish
    and also allowing me to edit records without messing up the sort order ?

    Thanks in advance !



    furry Guest

  2. Similar Questions and Discussions

    1. Filter records by date and time
      any chance to help me on this pls .. can anyone tell me how i can sort my table by date and time i wanna put down specific DATE and TIME into my db...
    2. Sort by Date (Latest Date that is)
      :confused; Hello I have an access db which has text feilds and has a date feild set to the default value of Now() I want to be able to filter a...
    3. How to display records from todays date and specifiec time of the day
      Hi all any idea how to display specific record on current date and time of the day ... i did managed to display it for the date and drop it on...
    4. Next-n Records Sort Problem
      Anyone? Bueller? Bueller?
    5. sort records in both ways
      How could records be sorted in both ascending in descending order in the same time? You can sort in either one direction or the other. "susie"...
  3. #2

    Default Re: dynamic time/date variable to sort records by

    *** furry wrote/escribió (Wed, 16 Jun 2004 14:12:00 +0100):
    > One problem. Whenever I need to edit the data in an already created blog
    > record, this automatically changes the time field (presumably because it's
    > of type TIMESTAMP). This screws up the sorting of my blogs.
    Exactly, that's the behaviour of TIMESTAMP fields. Anyway, please note that
    if you have more than one fields of TIMESTAMP type only the first one gets
    updated.
    > Can anyone suggest a way whereby I can store today's date in a format that
    > is sortable in descending order, allowing me to display records as I wish
    > and also allowing me to edit records without messing up the sort order ?
    You have DATE and DATETIME.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  4. #3

    Default Re: dynamic time/date variable to sort records by

    I figured this out myself.

    All I needed was to get a timestamp formatted date and post this to a text
    based field in my table.

    Here's the code to generate a timestamp using PHP:

    $timestamp = mktime
    (date('H'),date('i'),date('s'),date('n'),date('j') ,date('Y'));


    Works a treat


    "Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
    message news:wr3bghpq5w6d.1to31z04aro43.dlg@40tude.net...
    *** furry wrote/escribió (Wed, 16 Jun 2004 14:12:00 +0100):
    > One problem. Whenever I need to edit the data in an already created blog
    > record, this automatically changes the time field (presumably because it's
    > of type TIMESTAMP). This screws up the sorting of my blogs.
    Exactly, that's the behaviour of TIMESTAMP fields. Anyway, please note that
    if you have more than one fields of TIMESTAMP type only the first one gets
    updated.
    > Can anyone suggest a way whereby I can store today's date in a format that
    > is sortable in descending order, allowing me to display records as I wish
    > and also allowing me to edit records without messing up the sort order ?
    You have DATE and DATETIME.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --


    furry Guest

  5. #4

    Default Re: dynamic time/date variable to sort records by

    *** furry wrote/escribió (Wed, 16 Jun 2004 15:36:23 +0100):
    > Here's the code to generate a timestamp using PHP:
    >
    > $timestamp = mktime
    > (date('H'),date('i'),date('s'),date('n'),date('j') ,date('Y'));
    I normally leave leave the work to MySQL:

    .... date_field=NOW()

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  6. #5

    Default Re: dynamic time/date variable to sort records by

    On Wed, 16 Jun 2004 16:10:02 +0200, Alvaro G Vicario
    <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote:
    >*** furry wrote/escribió (Wed, 16 Jun 2004 14:12:00 +0100):
    >> One problem. Whenever I need to edit the data in an already created blog
    >> record, this automatically changes the time field (presumably because it's
    >> of type TIMESTAMP). This screws up the sorting of my blogs.
    >
    >Exactly, that's the behaviour of TIMESTAMP fields. Anyway, please note that
    >if you have more than one fields of TIMESTAMP type only the first one gets
    >updated.
    From MySQL.com
    ([url]http://dev.mysql.com/doc/mysql/en/TIMESTAMP_pre-4.1.html):[/url]
    .. . .
    You can set any TIMESTAMP column to a value different from the current
    date and time by setting it explicitly to the desired value. This is
    true even for the first TIMESTAMP column. You can use this property
    if, for example, you want a TIMESTAMP to be set to the current date
    and time when you create a row, but not to be changed whenever the row
    is updated later:

    Let MySQL set the column when the row is created. This initializes it
    to the current date and time.
    When you perform subsequent updates to other columns in the row, set
    the TIMESTAMP column explicitly to its current value:

    UPDATE tbl_name
    SET timestamp_col = timestamp_col,
    other_col1 = new_value1,
    other_col2 = new_value2, ...

    .. . . .

    Basically, instead of altering the database, it's saying to reuse the
    old timestamp.
    eclipsboi Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139