axyinogue Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/ Share on other sites More sharing options...
Lamez Posted December 23, 2008 Share Posted December 23, 2008 I am not sure, but I think you need a cron job Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721846 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 what do you mean by cron job? Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721875 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 cron is a scheduler for Linux. You can set it to execute scripts at given intervals. PHP has no way of doing this itself. Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721898 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 Linux? I am windows based guy and never touch Linux before, so do you have any idea? can you teach me? For simple example, how can I have a clock in my PHP application that can run exactly like our computer time? Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721905 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721909 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721926 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721934 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 ok, can you teach me how to link the windows scheduler and PHP? thx so much i really really really need help about this Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721936 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721941 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 it means it's not automatic, but the users want it automatically updated. Is there any other way? Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721951 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 it means it's not automatic, but the users want it automatically updated. Is there any other way? What do you mean its not automatic? Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721954 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 means no need to click any button Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721993 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 There is no need to click any button. Once the schedular is set it will automatically update your database every month. Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-721997 Share on other sites More sharing options...
axyinogue Posted December 23, 2008 Author Share Posted December 23, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-722067 Share on other sites More sharing options...
Mark Baker Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-722105 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138093-how-to-do-auto-update-in-database/#findComment-722125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.