Jump to content

How to do auto update in database?


axyinogue

Recommended Posts

I tried to create an inventory software for my office where it also can help to calculate the depreciation of the item, but how can i make the database auto update itself where the condition is when the current time changes the day then it will auto update certain data in the database?

Link to comment
Share on other sites

how can I have a clock in my PHP application that can run exactly like our computer time?

 

You can't. HTTP is stateless. PHP scripts are executed as they are requested.

 

For windows you can use scheduler, its in your control panel somewhere.

Link to comment
Share on other sites

So do you have any idea how can I have an invemtory system that can count the depreciation of an item by itself automatically where the depreciator is a constant amount? let say today I buy item A $1500 and then i put in a text box which determine the years of depreciation as 3 then every month it will depreciate by itself for amount of 1500 / (3 x 12) = 1500 / 36 = 41.666... means monthly it will minus the value by itself for 41.666...

Link to comment
Share on other sites

So do you have any idea how can I have an invemtory system that can count the depreciation of an item by itself automatically where the depreciator is a constant amount?

 

Yeah, store the price and depreciation period (in months) in your table then write a script to execute a query something like....

 

UPDATE tbl SET price = price - (price/depreciation);

 

Of course this script would then need to be executed monthly using either cron or windows scheduler as already suggested.

Link to comment
Share on other sites

You don't need php for this. I'm not a windows user so can't really be of a great deal of help but all you would need to is tell the schedular to execute the following command (edit to your needs) monthly.

 

mysql -uYOURUSERNAME -pYOURPASSWORD YOURDATABASE -e "UPDATE tbl SET price = price - (price/depreciation);"

Link to comment
Share on other sites

I am a PHP beginner, a newbie, can you tell me in detail? how to set the schedular to link up to PHP? don't just give me the short reply because I won't understand at all

How much do you understand Windows?

 

Write a php script that connects to the database and updates the records whenever it is run.

In Windows Control Panel/Administration Tools/Task Scheduler, create a new task that will run every month

    It should run: C:\<path\to\PHP> C:\<path\to\your\script>myScript.php

    Start directory should be C:\<path\to\your\script>

 

Depending on your PHP installation, you may need to point it to a specific php.ini file

 

Link to comment
Share on other sites

As I said earlier I'm not a windows user so I am unable to give you any step by step instructions on setting up schedular.

 

What I have done however is provide you with a complete and working query. I'll say it again, you do not need php for this job.

 

Have you even looked at the schedular? I said in my second reply that it is in your control panel somewhere.

 

Now you need to help us help you and at least attempt to piece all these pieces together.

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.