CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Update field with date of update.

Print topic Send  topic

Author Message
ispwebhosting4u

Posts: 17
Posted: 01/27/2004, 9:29 AM

Hello,
I know that this topic has been beaten into the ground before, but I can't seem to get it working right.
I have a site with events, and whenever someone makes a change to an event, I want to store the date it was modified in a field called date_update.

I am using CCS+PHP+MySQL

I have a record with a label call Label_date_update, that displays the last date the event was modified. I have a hidden field that is called date_update.

When an event is created, it is easy to set the Default Value for date_update to CurrentDateTime. That value is saved when the record,event, is added.

I have setup custom code in the BeforeShow event for date_update... I know I should have it in a before update event... I want to view the value placed in the hidden field before it is updated in the record.
Anyway, my code is:

global $record_name
$record_name->date_update->SetValue(ccsDate);

I tried using now() instead of ccsDate and got unknown function error now().

The above code gives me an incorrect date and time of 12/31/69, 06:00:04 PM. I think it is a formating problem.
I have the date format set as General Date, mm/dd/yyy H:nn:ss
DBFormat is yyyy-mm-dd HH:nn:ss

Does anyone have a working solution?
_________________
Rick Page
PageHosting4U.com
View profile  Send private message
Al
Posted: 01/27/2004, 12:28 PM

Hello,
Try to use time()
global $record_name  
$record_name->date_update->SetValue(time());  

ccsDate is a Constant
NOW() is a MYSQL function

Thanks
Al

ispwebhosting4u

Posts: 17
Posted: 01/27/2004, 1:09 PM

Thanks Al,
That did the trick.
_________________
Rick Page
PageHosting4U.com
View profile  Send private message
jstuart


Posts: 26
Posted: 01/28/2004, 8:58 AM

You could also setup the date_updated field to be a timestamp date and upon updating, set it to NULL. That way, the database itself updates the field for you.
_________________
Jeff Stuart
jstuart@computer-city.net
View profile  Send private message
BlakeSeven
Posted: 02/04/2004, 10:54 AM

I have the same problem, but with a record insert. I really want to be able to use the mysql now() funtion in the insert.

This used to work in the original CC, but doesn't in CCS. When you are in the Default value box, the small help box states, "Default value assigned for this control for new records. E.g. 1, "Bob", Now()
This is expanded apon in the help page regarding Default Value Property

However, if you do what the help suggests by putting Now() in the field you of course get the unknown function error because it is trying to treat Now() as a php function. Trying to work around this, the ccs code just continues to break, and send NULL, or the other values that ispwebhosting4u mentioned above.

In the end, what is really required, is a method to get an insert or an update send an unquoted mysql now() as a value in the insert/update statement sent to mysql.
DonB
Posted: 02/04/2004, 2:10 PM

That might be a deficiency in the CCS query builder - "Now()" is (as you
point out) not a valid function for MySQL - only Access as far as I know
will know what to do with it. I am not aware of CCS translating this into
database-specific equivalents (never looked, to tell the truth). You can
put in any expression you like, though, but just typing it in.

Please inquire about this via an email to support.codecharge.com and they
will either explain correct usage for your situation or record this as
something to be fixed in a future release.

--
DonB

http://www.gotodon.com/ccbth


"BlakeSeven" <BlakeSeven@forum.codecharge> wrote in message
news:540213fcd868f2@news.codecharge.com...
> I have the same problem, but with a record insert. I really want to be
able to use the mysql now() funtion in the insert.
>
> This used to work in the original CC, but doesn't in CCS. When you are in
the Default value box, the small help box states, "Default value assigned
for this control for new records. E.g. 1, "Bob", Now()
> This is expanded apon in the help page regarding Default Value Property
>
> However, if you do what the help suggests by putting Now() in the field
you of course get the unknown function error because it is trying to treat
Now() as a php function. Trying to work around this, the ccs code just
continues to break, and send NULL, or the other values that ispwebhosting4u
mentioned above.
>
> In the end, what is really required, is a method to get an insert or an
update send an unquoted mysql now() as a value in the insert/update
statement sent to mysql.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

BlakeSeven
Posted: 02/04/2004, 2:41 PM

Just to clarify...

Now() _is_ a valid function in MySQL, for example
Insert into MyTable (myname, mydatetimeofrecordinsert) Values ('BlakeSeven', Now())

However, Now() _is not_ a PHP function, which causes a PHP error if you attempt to use it as a default value in CCS.

The good thing about using the MySQL Now() function over the use of one of the CCS default value dropdowns, like CurrentDate, CurrentTime, or CurrentDateTime, is that you get the _true_ datetime of the insertion of the record. While if you use the CurrentDateTime drop down value, what happens is the date/time is calculated and put into the page when it is requested, NOT when it is submitted. So, if you go to a CCS created record page at Noon, but do not actually submit the page until hours later, the Noon date/time stamp is submitted rather than the actual time of submission.
Of course CurrentDateTime is great if you are showing a value to the user, whereas the use of Now() has more to do with back-end tracking.
Really, you wouldn't even want to have it as a form submitted value at all, even a hidden form value, but a control variable.

There must be a way to do this via a Before Insert. I think its worth a bit of documentation to show how to do it.

BlakeSeven
Posted: 02/18/2004, 2:32 PM

I was eventually able to find the answer in the CCS documentation under the heading, Dynamically Modify the SQL Statement.

I was able to use the example there to do the same with an Insert statement using Before Execute Insert, and placing in this custom code.

//Custom Code @59-5F6DD002
// -------------------------
global $builds;
$builds->ds->SQL = str_replace("INSERT INTO builds (", "INSERT INTO builds (bld_recorddatetime, ", $builds->ds->SQL);
$builds->ds->SQL = str_replace(") VALUES (", ") VALUES (now(), ", $builds->ds->SQL);
// -------------------------
//End Custom Code

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.