This topic is locked

Default date + 7

9/9/2006 7:59:31 PM
PHPRunner General questions
J
Jean author

Adding a date field in a new record, I would like that the default date value were calculated from the previous datefield recorded + 1 week (in the same table). Can anybody explain to the newbie I am how to do that in phprunner ? Thank you for any help.

Jean

T
thesofa 9/10/2006

do you want the new value to be 7 days after the date that was in the field?

Or do you want this value suggested for the firld and you can alter it if you want?

J
Jean author 9/10/2006

do you want the new value to be 7 days after the date that was in the field?

Or do you want this value suggested for the firld and you can alter it if you want?


I want this value suggested for the field with permission to alter it if I want.

T
thesofa 9/10/2006

which flavour of database are we talking here?

J
Jean author 9/10/2006

which flavour of database are we talking here?



Sorry to be clumsy. A simple mysql with just one table. Adding a new record, the user have to indicate a date. Generally, this date is the last date recorded in the previous record + one week. I would like to suggest him this date, letting him change if desired. Does it help ?

T
thesofa 9/10/2006



Sorry to be clumsy. A simple mysql with just one table. Adding a new record, the user have to indicate a date. Generally, this date is the last date recorded in the previous record + one week. I would like to suggest him this date, letting him change if desired. Does it help ?



now that is a bit different from the first post.

you said originally

Editing a date field, I would like that the default date value were calculated from the previous datefield recorded



this is different from the adding a new record.

Are we editing an existing record or adding a new record in the database?

There is quite a big difference <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10984&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

J
Jean author 9/10/2006



now that is a bit different from the first post.

you said originally
this is different from the adding a new record.

Are we editing an existing record or adding a new record in the database?

There is quite a big difference <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10985&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />



Adding <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10985&image=2&table=forumreplies' class='bbc_emoticon' alt=';)' />

T
thesofa 9/10/2006



Adding <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10986&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />



so the process will be

find last record

get date value from last record

add 7 days to it

make it as default value for editable field in add_form
If you break it down like this, you can search the forum for each action you need to do and find posts that will help you solve it.

If you need more help, just keep posting <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10986&image=2&table=forumreplies' class='bbc_emoticon' alt=':D' />

J
Jean author 9/10/2006



so the process will be

find last record

get date value from last record

add 7 days to it

make it as default value for editable field in add_form
If you break it down like this, you can search the forum for each action you need to do and find posts that will help you solve it.

If you need more help, just keep posting <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10987&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />



It becomes more clear, thanks. "find last record" or "last record" give no result in the forum. Not a good beginning. I'll try later.

T
thesofa 9/10/2006

It becomes more clear, thanks. "find last record" or "last record" give no result in the forum. Not a good beginning. I'll try later.



OK, have a look here and see if you can adapt the code to fit your case.

He is looking for the last ID number entered.

I assume you are using an ID field set to autoincrement as aprimary key?

If you find the last record like that, you can then extract the date field from it an assign it to a variable.

Once you have this in a variable, you can add 7 days to it using date_add

HTH

J
Jean author 9/10/2006



OK, have a look here and see if you can adapt the code to fit your case.

He is looking for the last ID number entered.

I assume you are using an ID field set to autoincrement as aprimary key?

If you find the last record like that, you can then extract the date field from it an assign it to a variable.

Once you have this in a variable, you can add 7 days to it using date_add

HTH



great, thanx you ! I begin to see the light <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10991&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> With
global $conn;

$rs = mysql_query("select max(date_init) from _PermanencesTableau",$conn);

$data = mysql_fetch_array($rs, MYSQL_NUM);

echo "Key value to be assigned: ".($data[0]);
I can echo the good value (I will add_date after basic tests)
I've put in place of echo
$date_init_default = ($data[0]);
and this default value in the step 7 of phprunner. It doesn't function. Perhaps because $date_init_default isn't global ? No, I tried. Here, I am out of the game because I don't understand clearly how phprunner builds his modules. Perhaps have I to change the event. I'll try.

J
Jane 9/11/2006

Jean,
use $_SESSION variables to pass value from event to other pages.

global $conn;

$rs = mysql_query("select max(date_init) from _PermanencesTableau",$conn);

$data = mysql_fetch_array($rs, MYSQL_NUM);

$_SESSION["max"] = $data[0];



And then use $_SESSION["max"] as default value on the Formatting tab.

J
Jean author 9/11/2006

Jean,

use $_SESSION variables to pass value from event to other pages.
And then use $_SESSION["max"] as default value on the Formatting tab.


It functions, great ! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10995&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> Thank you TheSofa, thank you Jane !