Jump to content


Photo

Ok 2 questions [SOLVED]


  • Please log in to reply
10 replies to this topic

#1 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 10:26 PM

Question 1. How can i make it so one of my pages cant be accessed dueing certon times? i.e the page will open at 8am and will close at 8pm once it is closed it will echo something like "We are closed we open at 8am and close at 8pm" can this be done?

Question 2. How can i make a random number like 0.003? the fact for this is i am making a gym for my game so i want a random number from 0.001 to 0.020. i tried this way but didn't work how i wanted it to.

<?PHP
$rand_strength = rand(0,0) . rand(0,0) . rand(1,20);

echo "You have gained $rand_strength strength";
$db->query("UPDATE users SET uStrength=uStrength+'$rand_strength' WHERE uID='" . $user['uID'] . "'");
?>

This is the results i got "You have gained 0018 strength"

Thanks for your time

#2 freeloader

freeloader
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 27 October 2006 - 10:39 PM

<?php
$hour = date('H');
if ($hour < 8){
echo "We are closed we open at 8am and close at 8pm";
}
elseif ($hour > 20){
echo "We are closed we open at 8am and close at 8pm";
}
else {
// normal page
}
?>

Watch out as '$hour' is the hour in server time of course, you might need to change that to match your time zone.

I'm not too sure about your second question, but something like this probably works:

<?PHP
$rand_strength = rand(0,0).".". rand(0,0).".". rand(1,20);

echo "You have gained $rand_strength strength";
$db->query("UPDATE users SET uStrength=uStrength+'$rand_strength' WHERE uID='" . $user['uID'] . "'");
?>

Good luck :)

#3 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 27 October 2006 - 10:40 PM

if you want to show a page only if it is between 8 am and 8 pm, then do this

<?php
$hr = date("G");
if($hr < 20 && $hr > 7){
//show the page
} else {
echo('Sorry, page closed');
}
?>

p.s. doublecheck the numbers in my if statement, they should be accurate but I'm not exactly certain.

also if you need to modify your timezone, say you're on PST and your server is EST, do this:

<?php
$hr = date("G");
$offset = $hr - 3;
?>

also, freeloader, when you put a date function in a variable, using " instead of ' is more error-proof

and the H format in date uses leading zeros, keep that in mind.
fuck it or fight it

#4 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 10:42 PM

Ok thanks for the replys guys.

Ill try them out and let ya know ;)

#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 27 October 2006 - 10:47 PM

1sr add in start of page
<?php
$h = date('H');
if ($h < 8 or $h > 20) exit('Not workin');
?>
2nd
$rand_strength = rand(1,20)/1000;


#6 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 10:51 PM

ok i aint tried the time one yet.

But the random number one works how i want it to now but for some reason it isnt updating the database with the $rand_strength

Any ideas?

#7 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 11:09 PM

ok i removed the /1000 and it updates the database fine :S so it has something to do with that :(

Hmm Dont mysql store like 1.010 in the database?

#8 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 27 October 2006 - 11:16 PM

is it type of field 'uStrength' float or integer?

#9 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 11:18 PM

uStrength  int(11)

Is this what u mean?

#10 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 27 October 2006 - 11:19 PM

ah i changed it to float and its workin now

Thanks

#11 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 28 October 2006 - 12:01 AM

generally in programming:

int = 1234567890 (no decimals)
float = 3.4 or 2.32135 etc. (a decimal)
fuck it or fight it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users