Jump to content

Updating mysql based on what day of the month it is


Greysoul

Recommended Posts

so im trying to setup a page for my bills that i pay monthly so me and my gf can access it remotely whenever we need to. we have a few loans that we are paying off in installment loans every month so i created a table like the picture below (which is actually in excel but it looks about the same).  i know how to pull via select and sum everything that i need but what i'm actually going for is this:

 

every month on those certain due dates i'd like for the monthly payment to be subtracted from the balance automatically..and it show the reflected balance. i'm not sure how to go about such a thing though as i've never worked with dates and times.  my logic is that i have to setup a beginning time stamp for it to work off of..and then every 30 days from that time stamp..subtract the payment.  then again, there's not always 30 days in a month and it'd get off track.  any ideas?

 

[attachment deleted by admin]

Link to comment
Share on other sites

Just a rough idea...

 

either set up a cron job on your server to run this script once a day, at say 3AM or you could setup windows task scheduler to start-your-brower-point-it-at-this-script once a day


/* add an integer field to your table - call it dueday */
/* in that field simply put the date due ie 1, 13, 27 etc */
/* you could also use a datetime field BUT it would require a little more 'complex' query */

/* get current day without leading zero*/
$current_day = date("j");

/* create query that updates all records where the record due date equals the current day */
$query = "UPDATE tablename set balance = balance-payment where dueday = '$current_day'";

/* execute the query */
$result = mysql_query($query);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.