Jump to content


Photo

Need help with a complex PHP code


  • Please log in to reply
4 replies to this topic

#1 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 29 August 2006 - 01:32 AM

I'm making a virtual pet site of sorts. I have the hunger of the pets stored as an integer 1 - 5. I need to make it increase by 1 every 24 hours or so. Then I need to make a list box that drops down with the number of pets the user has, with each one as an option. Then when you click on the pet, it gets rid of the food item associated with the list box and decreases the pet's hunger by 1. I have no idea how to do that though, does anyone know how I could do this? I don't know where to start...

Thanks!  :D
Schroedinger's Cat walks into a bar.
And doesn't.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 August 2006 - 02:08 AM

That's about several hundred questions, so I'll give you a starter on the 'every 24 hours' part.  Check you web host server control panel to see if/how a cron task can be run.  Cron tasks can be automatically scheduled to run at any recurring time you want.  If you are unfortunate enough to be running on a Windoze server, you'll need to look at the scheduler (whatever they call it) for the same functionality.
Legend has it that reading the manual never killed anyone.
My site

#3 DarkendSoul

DarkendSoul
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 29 August 2006 - 02:20 AM

An alternative methode of doing this would just having it check at the beginning of a show hunger request. Have something like...

$var = current time (in seconds) - time last fed (in seconds);
$lost_hunger = floor($var/(60*60*24));

if ($lost_hunger > $hunger_left) $pet = dead!;

then subtract that from the current hunger




#4 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 29 August 2006 - 03:04 AM

How would i make the list box part?
Schroedinger's Cat walks into a bar.
And doesn't.

#5 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 29 August 2006 - 03:39 PM

I think I've got the rest figured out,just need to figure out the listbox.
Schroedinger's Cat walks into a bar.
And doesn't.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users