Ask a Question related to PHP Development, Design and Development.
-
furry #1
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
-
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... -
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... -
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... -
Next-n Records Sort Problem
Anyone? Bueller? Bueller? -
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"... -
Alvaro G Vicario #2
Re: dynamic time/date variable to sort records by
*** furry wrote/escribió (Wed, 16 Jun 2004 14:12:00 +0100):
Exactly, that's the behaviour of TIMESTAMP fields. Anyway, please note that> 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.
if you have more than one fields of TIMESTAMP type only the first one gets
updated.
You have DATE and DATETIME.> 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 ?
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Alvaro G Vicario Guest
-
furry #3
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):Exactly, that's the behaviour of TIMESTAMP fields. Anyway, please note that> 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.
if you have more than one fields of TIMESTAMP type only the first one gets
updated.
You have DATE and DATETIME.> 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 ?
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
furry Guest
-
Alvaro G Vicario #4
Re: dynamic time/date variable to sort records by
*** furry wrote/escribió (Wed, 16 Jun 2004 15:36:23 +0100):
I normally leave leave the work to MySQL:> Here's the code to generate a timestamp using PHP:
>
> $timestamp = mktime
> (date('H'),date('i'),date('s'),date('n'),date('j') ,date('Y'));
.... date_field=NOW()
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Alvaro G Vicario Guest
-
eclipsboi #5
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:
From MySQL.com>*** 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.
([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



Reply With Quote

