djfox Posted October 21, 2007 Share Posted October 21, 2007 In a previous post, it was told to me to use time() for a function I`m working on. First, I`ll share the code: <?php $time= time(); if ($time=time()+3600) { $petfood= $rows[5] -2; mysql_query("UPDATE ownedpets SET food=$petfood WHERE id='$id'"); } ?> What this is supposed to do is subtract 2 from $rows[5] every hour. But instead what is happening is that 2 is subtracted from $rows[5] every time the page loads. Changing the time (right now it`s 3600) doesn`t affect it at all. Am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 To run a script every hour, you need to set up a cron job. You can completely take all that time() stuff out of your script. <?php $petfood= $rows[5] -2; mysql_query("UPDATE ownedpets SET food=$petfood WHERE id='$id'"); ?> Quote Link to comment Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 Cron job? I haven`t heard of those. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 You set them up with your host. Usually you can set them up from the control panel, it all depends on what host you use. Some hosts don't even offer cron jobs, so check that first. Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Read this http://www.lunarpages.com/new_manual/cronJobs.htm Or search google to find out what a cronjob is Also, in the code you posted, you didn't have == in your IF statement... just so you know Quote Link to comment Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 If my host doesn`t provide that, are there any alternatives? Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Here is a list of sites that may have your answer http://www.google.com/search?source=ig&hl=en&rlz=&q=alternatives+to+cron+jobs&btnG=Google+Search Quote Link to comment Share on other sites More sharing options...
igor berger Posted October 21, 2007 Share Posted October 21, 2007 Why do you need to update your database every hour? Are you feeding as pet? Quote Link to comment Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 Why do you need to update your database every hour? Are you feeding as pet? Yes, it`s for the virtual pet system I`m developing for my site. The hunger meter of all the pets need to go down by a time interval, to encourage the owners to feed the pet. Quote Link to comment Share on other sites More sharing options...
igor berger Posted October 21, 2007 Share Posted October 21, 2007 So why not force the time to be updated when the owner opens their account? Instead of push use pull to save on resources... Think about 100,000 owners, your script will run infinetly with push - cron job.. Quote Link to comment Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 Ok, my server does have cron jobs available. Next step most likely is learning it`s commands. Time to research. Thanks for the input guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.