PDA

View Full Version : Incremental Dates for each record


acaciasd344844
05-27-2009, 02:15 AM
Hi All,

I am afraid that I am not a php programmer, just a dreamweaver user with a DataAssist server behaviour.

I have created a page which allows users to set up a pre-selected number of pre-payments i.e 1-12, as well as frequency i.e 7, 14, 28 etc as well as a selected date i.e. this can be any date in the future.

This means that I need to enter the first date that they select into the first record then increment each date for the following number of records/pre-payments and the date should increment by the frequency.

I have used dataassist to create the multiple inserts but am stuck on how I should proceed.

So far, I have a hidden date field which I have added the following code...

<input name="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" type="hidden" id="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php $date = $row_Recordsetcustomers['date'];
$frequency = $row_Recordsetcustomers['frequency'];
$newdate = strtotime ( '+ 7 day' , strtotime ( $date) ) ;
$newdate = date ( 'Y-m-d H:i:s' , $newdate); echo $newdate; ?>[" />

The repeat selection counter is part of the dataassist server behaviour, so has to remain within the page. The section in bold is the code that I have added. The '+ 7 day' will be the frequency variable.

It appears to add the advanced date, not the initial selected date; and then adds this date to all the pre-payments/records.

Hopefully some one can guide me as to where I am going wrong!

Thanks in advance


John Henderson

Ray Borduin
05-27-2009, 06:44 AM
Add code to the top of the page just below the recordset, or at least somewhere above the loop like:

<?php $writeDate = $row_Recordsetcustomers['date']; ?>

Then in the form use:

<input name="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" type="hidden" id="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo date ( 'Y-m-d H:i:s' , $writeDate); ?>" />
<?php
$writeDate= strtotime ( '+ 7 day' , strtotime ( $writeDate) );
?>

acaciasd344844
05-27-2009, 08:39 AM
Add code to the top of the page just below the recordset, or at least somewhere above the loop like:

<?php $writeDate = $row_Recordsetcustomers['date']; ?>

Then in the form use:

<input name="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" type="hidden" id="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo date ( 'Y-m-d H:i:s' , $writeDate); ?>" />
<?php
$writeDate= strtotime ( '+ 7 day' , strtotime ( $writeDate) );
?>
Thanks will give it a go

john

acaciasd344844
05-28-2009, 01:48 AM
Hi Ray,

Thanks for your assistance with the php code; It works but not quite!
I added the code to where you recommended but the results for some reason are unexpected.
The date does appear in all the records, but they appear as the following

record1DATE 1970-01-01 01:33:29
record2DATE 2009-06-04 09:17:02
record3DATE 1970-01-08 01:00:00
record4DATE 1970-01-08 01:00:00
record5DATE 1970-01-08 01:00:00
record6DATE 1970-01-08 01:00:00


The system allows up to 12 records to be created at a time. I tested it a number of times, but the outcome is always the same. Confusing dates!


The additional require ment is that the No '7' in the code becomes a variable
+ 7 day, and this would be $row_Recordsetcustomers['frequency']

I could not get that to work either. I kept getting a parse error.

The frequency field can contain a number of different values, this is why it is needed.


Thanks again Ray, for your time and assistance


regards


john henderson

Ray Borduin
05-28-2009, 09:17 AM
Add code to the top of the page just below the recordset, or at least somewhere above the loop like:

<?php $writeDate = strtotime($row_Recordsetcustomers['date']); ?>

Yeah I based the code on the assumption that your code was basically working. I see now that you had a flaw in your logic when incrementing the date in general:

<input name="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" type="hidden" id="hf_date_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo date ( 'Y-m-d H:i:s' , $writeDate); ?>" />
<?php
$writeDate= strtotime ( '+ '.$row_Recordsetcustomers['frequency'].' day' , date('Y-m-d H:i:s' , $writeDate) );
?>

(incidentally I don't have time to test this, so you may need to do a little debugging if you run into problems. The concepts should be sound)

acaciasd344844
05-28-2009, 11:49 AM
Thanks Ray will give it a go in the morning UK time

will let you know the outcome

regards

john

acaciasd344844
05-28-2009, 11:58 AM
Thanks for what youve done Ray

I just wondered does this kind of principle reflect what i am after...

date = date + 1

because the code we have so far does not reflect this!

what do you think?

john

Ray Borduin
05-28-2009, 12:23 PM
I don't understand the question. That doesn't appear to be valid php code.

acaciasd344844
05-29-2009, 04:44 AM
Once again thanks for your able assistance, I would not have got this far without you.


I have managed to get the dates to increment and figured out how the system is looping etc.

It just appears now that the date the code is supposed to increment is replaced by '1970-01-01', obviously a system start time.

I have been really trying to get this to work but my lack of php knowledge is rather telling.

this is what i have so far...


*** I put the variable above the begin loop section:


<?php $writeDate = $row_Recordsetcustomers['date']; ?>
<?php
// RepeatSelectionCounter_1 Begin Loop



*** I created a visible test field so that I can see the results before they enter the system. This sits with the hidden fields

<input name="textfield" type="text" id="textfield" value="<?php echo date ('Y-m-d H:i:s' , $writeDate); ?>" />



*** I put the final bit of code in the RepeatSelectionCounter_1 End section


<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_Recordsetpayments && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_Recordsetpayments = mysql_fetch_assoc($Recordsetpayments);
$writeDate = strtotime('+7 days', $writeDate);
}
$RepeatSelectionCounter_1++;


} // RepeatSelectionCounter_1 End Loop

All this works except for the fact that the $row_Recordsetcustomers['date'] is not picked up and incremented and the following code you provide previously
stopped the increment from working altogether...

$writeDate= strtotime ( '+ '.$row_Recordsetcustomers['frequency'].' day' , date('Y-m-d H:i:s' , $writeDate) );


could all this be something to do with the php version I have? Or do I need to use Global variables?

Sorry to pester, Ray, but I have to have this bit done by the end of this month (gulp).

Once again thanks in anticipation


john

Ray Borduin
05-29-2009, 06:50 AM
The code on the top of the page should be:

<?php $writeDate = strtotime($row_Recordsetcustomers['date']); ?>

and to increment I think you are going to have to use:

$writeDate = strtotime('+7 days', date('Y-m-d H:i:s' , $writeDate));

you need to learn how to debug if you are going to try to write php code by hand. Have you tried adding die() and echo() statements to your code so you can check when and where things are going wrong? Are you looking for code examples on php.net and trying to adjust lines of code when there are errors?

I like helping, but debugging and writing custom code go hand in hand. You should learn debugging now before wasting this much time in the future. If you knew how to debug this problem would have been solved in the first hour of working on it and you wouldn't be worried about your deadline.

acaciasd344844
05-29-2009, 08:26 AM
Thank-You Ray