Session Start: Wed Sep 27 11:55:46 2000 *** Now talking in #netsurprise hello everyone :) Hey TDavid love your php courses, make a nice set of potd scripts * TDavid is just about off the phone thank you zoingk :) er zoink :) i gots to go post a note on netsurprise unless one of you nice folks would do for me? I think you are alone on it * TDavid checks the pulse of the room hehe, maybe it's just you and I zoink :) probably is :) I'm here :) hey WillyB hey willyB :) Hi ya ZoiNk and TD :) i was just about to give zoink all the really good coding secrets lol I did get this far TD... $today_is = date("l"); $today_num = date("w"); $month_day = date("j"); $month_max = date("t"); :((( Why the frown? http://4.3.125.62/php/calander.php3 I can't figure out how to make it count the saturdays ok, let's break down what we are trying to do ok we are trying to figure out what the calendar looks like for the month we'd like to be able to pick any day in the month and pull up a calendar from that information yep so the first thing we need to do is get today's date // what is today? $day = date("d"); $month = date("m"); $year = date("Y"); ok now let's print that out for demo purposes: print("Today is $month-$day-$year

"); ok, now we need to get the "ceiling" which is the last day of the calendar month we need to figure out what that is but if it is the 31st day we already KNOW it is the last day of the month, right? a simple conditional will take care of this for us if($day < 31) { $ceiling = lastDay($month, $day, $year); } else { // no need to call function if it is 31st day of the month $ceiling = 31; } you may notice i am calling a function called: lastDay() yeah I did this is a function that I created, it does not exist in the php library now we need to understand what this function does first it will use a built-in PHP function called checkdate() checkdate() will return true or false on any date between 1900 and 32764 if it is valid day, month and year so we can send today's date to the function and increment from today until the end of the month ... when we get to the last day of the month checkdate() will return false so we know it is the last day of the month *** ZoiNk has quit IRC (QUIT: User exited) and then we can return that value as the $ceiling if($day < 31) { $ceiling = lastDay($month, $day, $year); } else { // no need to call function if it is 31st day of the month $ceiling = 31; } so $ceiling = the last day of the month when checkdate() returns false as long as today isn't the 31 day of the month you with me? now let's look at the actual function code for lastDay() that does what I just described yeah, writing this all donw in my notes too :) function lastDay($emonth, $eday, $eyear) { $test=0; while($test < 1) { // is this a valid day for this month? if(checkdate($emonth, $eday, $eyear)) { $eday++; } else { // not a valid date $test=1; return($eday-1); } } } you can use this function in your own apps to calculate the ceiling for any month in any year between 1900 and 32764 you simply pass it a day, month, and year in 4-digit format i need the code after this part [14:14] ³TDavid³ } else { [14:14] ³TDavid³ // not a valid date ·¤· text flood from TDavid my script said you flooded me heh $test=1; return($eday-1); } } } ty we start a while() loop to execute through the days of the month until checkdate returns false and then we return which day that is to the $ceiling and leap year is calculated as well in that.. I noticed a leapyear arg in date() yes let's say we want to make a calendar for November k we pass like this: lastDate(11, 27, 2000); I can start at any day as long as it is less than 28 because we don't want to start with a day which is potentially out of range we know we won't get an out of range date because we will usually be passing TODAYs date but if you wanted to find out what the last day of November 2000 was you could use: $lastdayNov2000 = lastDate(11, 27, 2000); and it will tell you any questions on the use of this function? *** Wolfes-woman has joined #netsurprise we already know the floor or the first day of the month is equal to 1 but now we need to determine what the first day of the month DAY is I don't think so TD.. as long as it's a viable date lastdate will return the last day of them month.. that's right? correct and as long as you always feed from today's date you KNOW you have a valid date being returned k but you could use any day between 1 and 27 for future dates and it will work fine because we all know those are valid days of the month in any month in any year same for past dates back to 1900 ok next we need to figure out what day the first day of the month falls on in textual and numeric format textual is simply for display and not necessary to the script we do this using a built-in php function called mkdate(); right, the numeric is for the math $firstdayT = date("D", mktime(0,0,0,$month,1,$year)); // textual that will return Fri in this month's case :) next month that would return Sat $firstdayN = date("w", mktime(0,0,0,$month,1,$year)); // numeric there is the numeric date the 0,0,0 is the actual time we dont' need the integer time so we use 0,0,0 now let's display to the browser for the world to see ... // output the first day of the month for demonstration only print("The first numeric day of the month is 1 and falls on a $firstdayT ($firstdayN)"); 1 is really a constant since the first day of any month will always be 1 but the actual day of the week that it falls on will of course be a variable and we need to know that for the next step which is where you said you were getting hung up, WillyB but before we go into the loop to draw the calendar, we need to do the same thing for the $ceiling or the last day of the month $lastdayT = date("D", mktime(0,0,0,$month,$ceiling,$year)); // textual $lastdayN = date("w", mktime(0,0,0,$month,$ceiling,$year)); // numeric now for display purpose only we output to the browser // output the last day of the month for demonstration only print("
The last numeric day of this month is $ceiling and falls on a $lastdayT ($lastdayN)"); right you seeing where this is going? now we know the first day of the month and the last day of the month and what day of the week that the first day of the month falls on we have all the variables necessary to draw a valid calendar they are all numbers which is what we need to use in our loop $checkme = $lastdayN; $week=1; we create a variable called $checkme that will be used as a counter to determine when to increment the $week we start with week 1 ok] you can use while() or for() loop to do the next part, but I like the use of a for() loop because it keeps the incrementing on one line as you'll see here: for($i=1; $i < $ceiling; $i++) { if($checkme == 6) { $week++; $checkme=0; *** belle has joined #netsurprise $i is the day of the month as we increment through the month $ceiling we already know is the last day of the month right if $checkme == 6 then today is saturday and thus the last day of the month so we reset $checkme to equal zero and increment the week next if it is NOT saturday we do the following: *** belle has left #netsurprise } else { // increase the day of the week $checkme++; } if($i == $day) { // it's today so escape the loop break; } } ah, ok we increase the day of the week so in the next iteration of the loop we are examining a new day if $i equals today than we break from the loop and stop the examination you could do something different with this, which I'll show in a moment where you actually continue through with the loop to draw an actual calendar and highlight today ok, I'm still absorbing all you just said! hehehe you can see this calendar by clicking here: http://www.scriptschool.com/php/calwiz.phtml great !!!! the last step in our process is to do output which week today falls in: $day .= 'th'; print("

The $day day is in week #$week of this month"); ?> i concatenated the $day string so it says the 27th instead of the 27 day of the month the source code we just reviewed is on display here: http://www.scriptschool.com/php/weeks.phtml with very little modification I had the script draw the calendar I just showed you at the other url. I'll leave that exercise to you folks to do on your own if you want cool :) can u put up a .phps file? any questions on calculating calendar dates? if you goto http://www.scriptschool.com/php/weeks.txt You could use date("S"); to do that as well couldn't you td? you'll see the complete source code of what we just discussed excellent my stupid mIRC script kept ignoring you for text floods hmmm, i spose, yes 3 new functions to look up now :) hehehe lots of different ways to do this, but I have shown you one :) it is quite functional i started playing around and made a daytimer out of it lol I'll go through this and try to have that week3adv done today :) I didn't know it was that involved! well you can slice out the print statements, but yeah it isn't just a simple mathematic equation, unfortunately if you knew the leap year calculation you probably could convert a timestamp and go that way but that would be more complicated an algorithm im thinking I was going to bed thinking of how I could manipulate the day of the week and the day of the month to make it do it.. hehehe You could turn it into a seperate function really yeah, we should turn this into a calendar alert project...where it tells us "Don't forget about scriptschool chat today"...."Meeting with prostitute tonight at 8pm" etc... LOL JakeJ! hehe http://www.adultnetsurprise.com/learning_center/php/php_week_4.html you guys seemed to not have any difficulty with random numbers, besides whether mt_rand() would work i have had trouble with mt_rand() working on different configurations that's why i showed the slower srand() function week 4 was a little easier than 3 I have to admit! week 5 you should have no trouble with, it is basically on forms which is HTML and loops What Jake did in his randdom ( I think it was you jake) using 10000 for the seed instead of time.. it that what that was? he is grabbing the micro time instead of the time same concept, but a bit more precise than the integer second in time() ok, that's right.. what is micro time? Oh... using 10th or 100ths of a second? yes it's a function microtime() ... microseconds on the system clock i think it showed microtime in the manual for doing a random number i think it is 1000ths I C..I did notice when I refreshed mine fast it would bring back up the same banner a few times sometimes don't quote me on that though hehe well it is possible you got the same number thousandhths, ok if you do a little loop next week and use time() you'll find that over 10,000 generations you end up with less than 1/1000th of a percent off microtime is a little more precise yeah, srand() in the manual shows microtime It seems to do it most of the time when I refresh really fast I'll have to read that Jake bookmark the manual on your HD :) it comes in very handy right below phpbuilder forum It already is JakeJeck! hehehe srand(time()); while($i < 1000) { $number = rand(1,10); print(" $number"); if($number == 5) { $average++; } $i++; } print("5 came up $average times out of 1000"); try executing something like that someday then do the same thing with microtime and the same using mt_rand() and mt_srand() in place of srand() and rand() ah you'll find the results interesting if you go from 1000 to 10,000 to 100,000 a word of warning, do 100,000 on your LOCAL machine not a server hehe small hit, but it is a cpu hit *** MissGwendolyn has joined #netsurprise you could add if($i == 5000) { sleep(2); } to let the cpu take a tiny break in between hehe *** SurpriseBot sets mode: +o MissGwendolyn Hello =) hi missG ok, so if I exitcute this right now, will I still be here to tell you what happened? hehehe Hello MissGwendolynC srand(time()); while($i < 10000) { $number = rand(1,10); print(" $number"); if($number == 5) { $average++; } $i++; if($i == 5000) { sleep(2); } } print("5 came up $average times out of 1000"); yes :) it's not a very complex cpu calculation it will generate 10,000 numbers in a few seconds or less not doing any NASA type math :) it is the browser print that takes most the time it's quick if you remove the browser print in the loop then you could generate 100,000 number in a little over 1 second cool 5 came up 103 times out of 1000 computers are very very fast :) 5 came up 98 times out of 1000 should range from 95 - 105 pretty close hehehe out of 1000 just about every time out of the box yes how do you figure that? it should come up 100 times I see law of mathematics hehe nevermind after infinite trials hehehehe law of large numbers very useful in poker but if you do the same with 10,000 you'll notice the range is 98-102, and 100,000 it is 99 or 100 and if you do 1,000,000 it is 100 get's more precise the higher you go up yup Are yo making a planet ephemeris TD? cool i don't even know what that is lol Oh what is it? :) will try 1,000,000 without the print statement It plots the planets in their course as seen from the earth The naval obsvatory has a computer doing that and give it in long and lat ahhh, boy let the nasa and naval dudes figure out those calculations LOL!!! i have been reading this advanced algorithm book for 2 years and i still can't understand even 10% of it Using what they come up with and putting in to from looking up on a given long and lat, that's some pretty deep math in it's self1 that million test takes a while on my amd 350 The Schwartzian Transform is a cache technique that lets you perform the time consuming preprocessing stage of a sort only once when i think of schwartzian i'm thinking that would be a good name of a beer hehe *** floppy has joined #netsurprise instead it was some genius sitting around theorizing about time and space :) i have much respect for these folks but I do not understand 90% of what they theorize about lol hehehe TD Hi ya floppy!! ;) hey floppy :) 10,000 is pretty quick hello floppy Fatal error: Maximum execution time of 30 seconds exceeded in /home/httpd/htdocs/php/trythis.php3 on line 8 :(( you can do: settimeout(500); willyB LOL TD.. it couldn't do it on a 200! Ok 99.41% on 100,000 trials * floppy pulls out the good old caculator for these lessons lol 98.36% that time... That's an undefined function td er that is ... set_time_limit(500); // gives you 500 seconds before timeout ok. put it anywhere, or in the loop? no not in the loop! hehe * WillyB has very little experience! just before the loop :) LOL! ok! :)) that might crash ya, got to be careful with that function hehe I can see that it might! 105 came up 100401 times out of 1000000 i've done it a couple times unfortunately :(( it is easier to do than you might think when you are working with complicated nested loops but for most web based programming you'll never get up into 10,000 lines of code stuff I don't think I'd live long enough to write that many lines! well does anybody have any general questions about the course #4 text? i know it still doesn't point to the course :( i have to get kaiser to see if he can change that for us morn *** SleepWalker is now known as TimeWalker hi tw, how are you? :) are we going to build on it and add say impression, clicks counters? After you helped with the multidiminsional array TD, it went pretty smoothly for me Morning/afternoon TW :) the banner program? yes in week 16 your last assignment is a full free for all link list with banning, click counting, etc and an admin area to add/delete banners and view banner stats? cool and admin area :) only 4 weeks and you guys can already do quite a bit, i'm impressed! :)) pretty soon I'll be taking lessons from you guys lol hmm Your a great teacher TD :) But, we are great students too! hehehe i'm trying to do the 1,000 test 10 times inside another while loop but it's giving 111 times out of 1000 all 10 times...never changes hmmm, something out of whack while($x < 10) { srand ((double) microtime() * 1000000); then regular loop i'll see you guys in script school if you want to chat further ... im gonna go call kaiser, thank you for coming ... and i'll see you on Friday for the radio gaga version hehe Session Close: Wed Sep 27 13:15:49 2000