Jump to content

Archived

This topic is now archived and is closed to further replies.

R1der

Ok 2 questions [SOLVED]

Recommended Posts

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.

[code]<?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'] . "'");
?>[/code]

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

Thanks for your time

Share this post


Link to post
Share on other sites
[code]
<?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
}
?>[/code]

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:

[code]
<?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'] . "'");
?>
[/code]

Good luck :)

Share this post


Link to post
Share on other sites
if you want to show a page only if it is between 8 am and 8 pm, then do this

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

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:

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

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.

Share this post


Link to post
Share on other sites
Ok thanks for the replys guys.

Ill try them out and let ya know ;)

Share this post


Link to post
Share on other sites
1sr add in start of page[code]<?php
$h = date('H');
if ($h < 8 or $h > 20) exit('Not workin');
?>[/code]
2nd[code]$rand_strength = rand(1,20)/1000;[/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
is it type of field 'uStrength' float or integer?

Share this post


Link to post
Share on other sites
generally in programming:

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

Share this post


Link to post
Share on other sites

×

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.