R1der Posted October 27, 2006 Share Posted October 27, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/ Share on other sites More sharing options...
freeloader Posted October 27, 2006 Share Posted October 27, 2006 [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 :) Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115611 Share on other sites More sharing options...
Skatecrazy1 Posted October 27, 2006 Share Posted October 27, 2006 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-proofand the H format in date uses leading zeros, keep that in mind. Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115612 Share on other sites More sharing options...
R1der Posted October 27, 2006 Author Share Posted October 27, 2006 Ok thanks for the replys guys.Ill try them out and let ya know ;) Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115613 Share on other sites More sharing options...
sasa Posted October 27, 2006 Share Posted October 27, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115615 Share on other sites More sharing options...
R1der Posted October 27, 2006 Author Share Posted October 27, 2006 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_strengthAny ideas? Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115618 Share on other sites More sharing options...
R1der Posted October 27, 2006 Author Share Posted October 27, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115626 Share on other sites More sharing options...
sasa Posted October 27, 2006 Share Posted October 27, 2006 is it type of field 'uStrength' float or integer? Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115628 Share on other sites More sharing options...
R1der Posted October 27, 2006 Author Share Posted October 27, 2006 uStrength int(11) Is this what u mean? Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115629 Share on other sites More sharing options...
R1der Posted October 27, 2006 Author Share Posted October 27, 2006 ah i changed it to float and its workin nowThanks Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115631 Share on other sites More sharing options...
Skatecrazy1 Posted October 28, 2006 Share Posted October 28, 2006 generally in programming:int = 1234567890 (no decimals)float = 3.4 or 2.32135 etc. (a decimal) Quote Link to comment https://forums.phpfreaks.com/topic/25356-ok-2-questions-solved/#findComment-115643 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.