School Map:
Home / Enroll
$ Student Records; Class
$ News @ LIVE
Tech Radio * Support/FAQ
| Store | FORUMS
Class / Forums / php101 ![]() |
Post your Week 2 Basic To-Do Assignment here |
|
TDavid
|
Your Week #2 Basic TO-DO assignment should be posted here in this thread only. If you have specific questions about the week 2 course text then please also post them in this thread so that other students can learn from the information. General questions about Script School should be posted in the homeroom forum.
TO-DO ASSIGNMENT: Write a script to print to the browser a different url each day of the week using the switch and case statement.
|
|
Donnie
|
I did the week 2 basic assignment, but I keep getting a parse error pn line 11. Help!!!
<HTML> <HEAD> <TITLE>SchoolScript.com Assignment 2 - URL of the Day</TITLE> </HEAD> <BODY> <?php // This program will use the switch function to display a different url each day. // Get the numerical day of the week and assign it to a variable $today = date("w") // Assign urls and descriptions to variables. $sunlink = "<A HREF = http://www.dandrenterprises.co...gt;</A>"; $sunlinkdesc = "D and R Enterprises"; $monlink = "<A HREF = http://www.eoepa.org></A>"; $monlinkdesc = "Eastern Ozarks Environmental Preservation Association"; $tueslink = "<A HREF = http://www.scriptschool.com></A>"; $tueslinkdesc = "Script School"; $wedlink = "<A HREF = http://www.hotsheet.com></A>"; $wedlinkdesc = "Hot Sheet"; $thurlink = "<A HREF = http://www.ytmag.com/cgi-bin/a...gt;</A>"; $thurlinkdesc = "Yesterday's Tractors Auction"; $frilink = "<A HREF = http://www.ebay.com></A>"; $frilinkdesc = "ebay"; $satlink = "<A HREF = http://www.neargeekhosting.com...gt;</A>"; $satlinkdesc = "neargeek web hosting"; // SWITCH switch ($today) { case 0: print ("Today's link is: " . $sunlinkdesc<br> . $sunlink); break; case 1: print ("Today's link is: " . $monlinkdesc<br> . $monlink); break; case 2: print ("Today's link is: " . $tueslinkdesc<br> . $tueslink); break; case 3: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); break; case 4: print ("Today's link is: " . $thurlinkdesc<br> . $thurlink); break; case 5: print ("Today's link is: " . $frilinkdesc<br> . $frilink); break; default: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); ?> </BODY> </HTML> |
|
TDavid
|
You are missing the terminator on this line:
$today = date("w") It should read: [php] $today = date("w"); [/php] When you post your assignments, make sure to use the code tag so the board will format it properly. It will also display the code in color format and that can make it easier to spot errors like the one above. Keep up the good work :) |
|
TDavid
|
er, in my example above, be sure to use the word code instead of php for the color coding.
|
|
Donnie
|
I fixed the one problem, but now there is another parse error in line 28. I also do not understand what you mean about using the code tag to make the pasted code appear right. Sorry to be a pain.
<HTML> <HEAD> <TITLE>SchoolScript.com Assignment 2 - URL of the Day</TITLE> </HEAD> <BODY> <?php // This program will use the switch function to display a different url each day. // Get the numerical day of the week and assign it to a variable $today = date("w"); // Assign urls and descriptions to variables. $sunlink = "<A HREF = http://www.dandrenterprises.co...gt;</A>"; $sunlinkdesc = "D and R Enterprises"; $monlink = "<A HREF = http://www.eoepa.org></A>"; $monlinkdesc = "Eastern Ozarks Environmental Preservation Association"; $tueslink = "<A HREF = http://www.scriptschool.com></A>"; $tueslinkdesc = "Script School"; $wedlink = "<A HREF = http://www.hotsheet.com></A>"; $wedlinkdesc = "Hot Sheet"; $thurlink = "<A HREF = http://www.ytmag.com/cgi-bin/a...gt;</A>"; $thurlinkdesc = "Yesterday's Tractors Auction"; $frilink = "<A HREF = http://www.ebay.com></A>"; $frilinkdesc = "ebay"; $satlink = "<A HREF = http://www.neargeekhosting.com...gt;</A>"; $satlinkdesc = "neargeek web hosting"; // SWITCH switch ($today) { case 0: print ("Today's link is: " . $sunlinkdesc<br> . $sunlink); break; case 1: print ("Today's link is: " . $monlinkdesc<br> . $monlink); break; case 2: print ("Today's link is: " . $tueslinkdesc<br> . $tueslink); break; case 3: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); break; case 4: print ("Today's link is: " . $thurlinkdesc<br> . $thurlink); break; case 5: print ("Today's link is: " . $frilinkdesc<br> . $frilink); break; default: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); ?> </BODY> </HTML> |
|
Donnie
|
[code]
<HTML> <HEAD> <TITLE>SchoolScript.com Assignment 2 - URL of the Day</TITLE> </HEAD> <BODY> <?php // This program will use the switch function to display a different url each day. // Get the numerical day of the week and assign it to a variable $today = date("w"); // Assign urls and descriptions to variables. $sunlink = "<A HREF = http://www.dandrenterprises.co...gt;</A>"; $sunlinkdesc = "D and R Enterprises"; $monlink = "<A HREF = http://www.eoepa.org></A>"; $monlinkdesc = "Eastern Ozarks Environmental Preservation Association"; $tueslink = "<A HREF = http://www.scriptschool.com></A>"; $tueslinkdesc = "Script School"; $wedlink = "<A HREF = http://www.hotsheet.com></A>"; $wedlinkdesc = "Hot Sheet"; $thurlink = "<A HREF = http://www.ytmag.com/cgi-bin/a...gt;</A>"; $thurlinkdesc = "Yesterday's Tractors Auction"; $frilink = "<A HREF = http://www.ebay.com></A>"; $frilinkdesc = "ebay"; $satlink = "<A HREF = http://www.neargeekhosting.com...gt;</A>"; $satlinkdesc = "neargeek web hosting"; // SWITCH switch ($today) { case 0: print ("Today's link is: " . $sunlinkdesc<br> . $sunlink); break; case 1: print ("Today's link is: " . $monlinkdesc<br> . $monlink); break; case 2: print ("Today's link is: " . $tueslinkdesc<br> . $tueslink); break; case 3: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); break; case 4: print ("Today's link is: " . $thurlinkdesc<br> . $thurlink); break; case 5: print ("Today's link is: " . $frilinkdesc<br> . $frilink); break; default: print ("Today's link is: " . $wedlinkdesc<br> . $wedlink); ?> </BODY> </HTML> [/code] OK I got it now. |
|
Donnie
|
I have still been working diligently on the week 2 basic assignment. I still can't get it to work. I have made some changes to take small steps toward the actual assignment, but I just can't get there. Can you help with this code below, then I will work from there to complete the assignment as it should be. Thanks.
[php] <HTML> <HEAD> <TITLE>ScriptSchool.com Assignment 2 - URL of the Day</TITLE> </HEAD> <BODY> <?php // This program will use the switch function to display a different url each day. // Get the numerical day of the week and assign it to a variable $today = date("w"); // Assign urls and descriptions to variables. $sunlink = "<A HREF = http://www.dandrenterprises.co...gt;</A>"; $sunlinkdesc = "D and R Enterprises"; $monlink = "<A HREF = http://www.eoepa.org></A>"; $monlinkdesc = "Eastern Ozarks Environmental Preservation Association"; $tueslink = "<A HREF = http://www.scriptschool.com></A>"; $tueslinkdesc = "Script School"; $wedlink = "<A HREF = http://www.hotsheet.com></A>"; $wedlinkdesc = "Hot Sheet"; $thurlink = "<A HREF = http://www.ytmag.com/cgi-bin/a...gt;</A>"; $thurlinkdesc = "Yesterday's Tractors Auction"; $frilink = "<A HREF = http://www.ebay.com></A>"; $frilinkdesc = "ebay"; $satlink = "<A HREF = http://www.neargeekhosting.com...gt;</A>"; $satlinkdesc = "neargeek web hosting"; // SWITCH switch ($today) { case 0: print($sunlink); print ($sunlinkdesc); break; case 1: print($monlink); print($monlinkdesc); break; case 2: print($tueslink); print($tueslinkdesc); break; case 3: print($wedlink); print($wedlinkdesc); break; case 4: print($thurlink); print($thurlinkdesc); break; case 5: print($frilink); print($frilinkdesc); break; default: print($satlink); print($satlinkdesc); ?> </BODY> </HTML> [/php] |
|
TDavid
|
Hi Donnie
You should be able to add: [ code ] code goes here [ /code ] Just remove the spaces between the brackets and make sure that the colorize checkbox is checked. This way I can review your actual source code instead of the version that is being converted by the board |
|
TDavid
|
BTW, what you did in message #38 looks right, but I think maybe you didn't check the colorize code box? |
|
Donnie
|
Colorize is checked. No spaces inside brackets. When I previewed post #38, it was colorized, when I posted it, it wasn't. I am not going to previewit this time, just submit it. Hopefully then you will be able to look at what I have done and give me a hint as to why the program will not work. I am getting a parse error on the last line. Thanks. |
|
TDavid
|
Hi Donnie,
You are missing the closing bracket for your switch case statement. That's why you are getting an error. Needs to be like this: |
|
Donnie
|
Thanks TDavid. I just couldn't see that I had left that bracket off. It was about to drive me nuts. Below is the completed code. I think it partially fulfills the requirements for the advanced assignment. I'm off to try it.
|
|
ipcn
|
Okay, i keep getting errors on Line 7 & 9 when using this script. Any ideas?
[php] <html> <head> <title>URL of the day</title> </head> <body> <? //Get the day and store it $day = date("w"); //Now, get the URL for each day and store it switch($day) { case "0": $url = "http://www.ipcn.co.uk"; break; case "1": $url = "http://www.ps2zone.tk"; break; case "2": $url = "http://www.scriptschool.com"; break; case "3": $url = "http://www.google.com"; break; case "4": $url = "http://www.nichnet.co.uk"; break; case "5": $url = "http://www.dot.tk"; break; case "6": $url = "http://www.food.com"; break; default: $url = "#"; } //Now get a Title for each URL switch($day) { case "0": $title = "IPC Network"; break; case "1": $title = "PS2 Zone"; break; case "2": $title = "ScriptSchool"; break; case "3": $title = "Google"; break; case "4": $title = "NichNet"; break; case "5": $title = "DotTK"; break; case "6": $title = "Food.com"; break; default: $title = "ERROR: Please Refresh"; } //Now, a description switch($day) { case "0": $desc = "The International People's Chat Network"; break; case "1": $desc = "PS2 Zone, Your #1 Source for PS2 Chat, Games, and other things!"; break; case "2": $desc = "The best place to find tutorial to learn a new Scripting Language"; break; case "3": $desc = "Google -- World's #1 Search Engine"; break; case "4": $desc = "Great Free Hosting"; break; case "5": $desc = "Get a free .tk domian name"; break; case "6": $desc = "Food.com, your definitive guide"; break; default: $desc = "ERROR: Please Refresh"; } //Now, lets print it out print("<a href="$url">$title</a><br><br>$desc"); //End script ?> [/php] |
|
Sk8rRIMuk
|
Heres my script:
|
|
MasterD
|
I'm not sure if I was supposed to do it like this, but I think the assignment was this ? |
|
MasterD
|
Sorry for the tripple post .... I guess I should stop using the back button on this site
My apoligies, It was not my intention to spam |
|
TDavid
|
Re #46, ipcn:
quote: You have backslashes in front of the double quotes right? |
|
jthwalker
|
<HTML>
<HEAD> <TITLE>Assignment Week 2 - Different URL Each Day </TITLE> </HEAD> <BODY> <? // Program to display a different URL for each day of the week //listing day of the week from 0-6 $day = date("w"); //links and link info $day0="$day's Site of the Day is: <p> <a href='http://www.sosaenterprises.com'> http://www.SOSAEnterprises.com </a> My OWN web design business!"; $day1="$day's Site of the Day is: <p> <a href='http://www.pmin.net'> http://www.pmin.net</a> My site - The William P. Brewer Memorial Purple Martin Information Network"; $day2="$day's Site of the Day is: <p> <a href='http://www.lifehouse.150m.com'> http://www.lifehouse.150m.com</a> My web-based church!"; $day3="$day's Site of the Day is: <p> <a href='http://www.vilitas.com'> http://www.vilitas.com </a> My web host!"; $day4="$day's Site of the Day is: <p> <a href='http://www.scriptschool.com'> http://www.scriptschool.com</a> Scripting Instruction At it's Best!"; $day5="$day's Site of the Day is: <p> <a href='http://www.abcnews.com'> http://www.abcnews.com </a> ABC News!"; $day6="$day's Site of the Day is: <p> <a href='http://www.yahoo.com'> http://www.yahoo.com </a> Yahoo! Search Engine!"; //Now the switch/case part switch("$day") { case "0": print("$day0"); break; case "1": print("$day1"); break; case "2": print("$day2"); break; case "3": print("$day3"); break; case "4": print("$day4"); break; case "5": print("$day5"); break; case "6": print("$day6"); break; } ?> </BODY> </HTML> Is my script ok? I didn't really understand about the layout of the links on switch case, but tried to follow along as I studied the other students work. |
|
TDavid
|
jthwalker - what didn't you understand about the switch / case? I'd recommend including a default case.
|
|
TecBrat
|
I think I managed to get all the points of the assinment, using only one print function, and concatenating the string.
|
|
TecBrat
|
well, I did use a second print statement, but that was just to report a possible error. |
|
operations
|
|
|
Nazz
|
Ok Finally, It seemed real confusing at first but after looking at the others and working with it for a while I have it. Only using 1 print function had me going for a while! I do have a couple questions, What if I wanted to change the site of the day to site of the week? switch($week)? Also I dont really understand the default for sure. can I get a little explanation what it actually does? I included it as print error but doesn't php give you a line error anyway? Thankz Nazz
<html> <head> <title>Nazz's Second Assignment</title> </head> <body> <center>Nazz's Second Assignment.<br> <center> <? $today="date(w)"; switch($today) { case 0: $site = "Sunday Site of the Day<br>Free Web Hosting: <a href='http://www.t35.com'>T35 </a>"; break; case 1: $site = "Monday Site of the Day<br>Game Maker: <a href='http://www.gamemaker.nl/'>Game Maker</a>"; break; case 2: $site = "Tuesday Site if the Day<br>Google: <a href='http://www.google.com/'>Google</a>"; break; case 3: $site = "Wednesday Site of the Day<br>Free Hosting: <a href='http://www.tripod.lycos.co.uk/taketour/freehosting/'>Tripod</a>"; break; case 4: $site = "Thursday Site of the Day<br>3D software: <a href='http://www.legus3d.com/'>3D Software</a>"; break; case 5: $site = "Friday Site of the Day<br>Cheap Domain Names: <a href='http://www.voxdomains.com/'></a>"; break; case 6: $site = "Saturday Site of the Day<br>Adrift: <a href='http://www.adrift.org.uk/'>Adventure Game Developement</a>"; break; default: print ("error"); } print ("A Different WebSite Every Day:<br> $site"); ?> </body> <html/> |
|
Quicksaver
|
hi again, just a lil note for those who know what i mean... why werent arrays introduced in this course? it would be so much easier ;D
working url |
|
Quicksaver
|
by the way, i noticed a discordance from the assignement instructions here and in the tutorial itself, for example one says that only one print fuction can be used and the other doesnt specify. i followed the one on the tutorial because the one "up there" needs a bit more code (a print line for each "case" and the one i used only needs one print line)
just thought you might wanna check it out :) |
|
Shrek
|
Hi, Here is my assignment
<Title>Assignment 02 Script School - URL of the Day</title> <? // Just a simple assignment $sunurl="http://www.cnn.com"; $monurl="http://www.yahoo.com"; $tueurl="http://hk.tom.com"; $wedurl="http://www.hongkong.com"; $thuurl="http://www.pumb.org"; $friurl="http://www.mingpao.com"; $saturl="http://jeffkwan.blogspot.com"; $today=date("j/n/y"); $weekday=date("w"); print("The current date is: "); print(date("j/n/Y")."<br>"); //choose the day of url switch($weekday) { case 0: $printlink=$sunurl; break; case 1: $printlink=$monurl; break; case 2: $printlink=$tueurl; break; case 3: $printlink=$wedurl; break; case 4: $printlink=$thuurl; break; case 5: $printlink=$friurl; break; case 6: $printlink=saturl; break; } ?> <p><strong><small><font face="Arial">Output to HTML</font></small></strong></p> <p><small><font face="Arial">Try to mix it html with php.<br> Today Link is <? print($printlink); ?> </font></small></p> |
|
MarcusD79
|
I hope someone looks at this. I have having an awful time and have tried many diff ways of doing this. The problems seems to be just after my first link. I am also having trouble getting the other post to work as html, some I can get .php. |
|
Shrek
|
I have tried your php.
In the switch case.
|
|
Shrek
|
I have made a mistake for reply the message.
case0: should change to case 0: case1: should change to case 1: . . . Hope this can help u. |
|
MarcusD79
|
Thanks for you input Shrek, but it seems to still not work. Do you know if the Principal still comes on here? |
View Previous Thread Print This Page |
School Map:
Home / Enroll
$ Student Records; Class
$ News @ LIVE
Tech Radio * Support/FAQ
| Store
Advertising
| Link To Us | Privacy
Copyright 2000-2002 Script School Productions / KMR
Enterprises
No part of this website may be reproduced, copied and/or distributed
in any medium
without express written permission