School Map:
Home / Enroll
$ Student Records; Class
$ News @ LIVE
Tech Radio * Support/FAQ
| Store | FORUMS
|
Quicksaver
|
marcus, first you need to set two variables for your script to work, one is the one you already have: $_today=date("w"); and the other is like this: $_today2=date("l"); <-- lowercase "L"
now on the day strings you should change the $_today to $_today2 so it prints the name of the day instead of the number of the day like so: $_sun0="$_today2 s Link is to <a href=\"http://www.fagfrat.com/photos\">Photo Page</a>."; and so on for the rest of them next there's another error, you need to quote the value after the case condition: case "0": so your code should come out something like this:
also please dont forget to also post an url link to a copy of the script from now on, they're gonna get a lil bit more complicated and we cant just see the code to correct it, no one's that good :) |
|
Quicksaver
|
oops, sorry :P, somethin like this:
|
|
MarcusD79
|
Thanks Quicksaver, I made the adjustments but it does not seem to work. Well, that is part true, the .php now works. There seems to be a problem with the html and php working together. After getting the php to work I realized I had forgoten </head>, but it turns out to not have been the problem. I have also found that case 0: does not need to be case "0"; to work. Well here is a link to the working php:
http://www.fagfrat.com/phpclass/week2a.php
and here is one to the not working php in html: http://www.fagfrat.com/phpclass/week2a.html The problem seems to be here in this line: $_sun0="$_today2 s Link is to <a href=\"http://www.fagfrat.com/photos\">Photo Page</a>."; Well here is my whole code again.
|
|
Shrek
|
Marcus, I have tried your scripts.
When I copied the whole scripts to a file named temp.html. It has error. But when I rename the file to temp.php. It works fine and give accurate result. Hope this help u. |
|
MarcusD79
|
Shrek, was it really that simple? I had assumed that since we were putting php in html then it was to be a html file. DOH. Well, thanks for your help, I also have it working and have kicked myself. |
|
amiller
|
<TITLE>2</TITLE>
<center> <?php $today=date("w"); $comment="todays link is: "; switch($today) { case "0":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "1":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "2":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "3":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "4":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "5":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; case "6":$url = "<a href=\"http://www.google.com\">Google</a><br>Google search engine"; break; } print $comment . $url; ?> |
|
merlin69
|
I have a working demo <a href="http://www.realm-of-merlin.com/school/week2.php">Click here</a> |
|
canadian
|
ive check and double checked but i still can't find what wrong, the error is on line 11.
<html> <head> <title>Week 2 For PHP Learning Course: Assignment 2</title> </head> <body> <? $today = ("w"); switch($today) { case "0": $url = "<a href= "http://www.Sunday.com">Sunday</a>"; $des = "It's Sunday"; break; case "1": $url = "<a href= "http://www.Monday.com">Monday</a>"; $des = "It's Monday"; break; case "2": $url = "<a href= "http://www.tuesday.com">tuesday</a>"; $des = "It's tuesday"; break; case "3": $url = "<a href= "http://www.wednesday.com">wednesday</a>"; $des = "It's wednesday"; break; case "4": $url = "<a href= "http://www.thursday.com">Thursday</a>"; $des = "It's Thursday"; break; case "5": $url = "<a href= "http://www.Friday.com">Friday</a>"; $des = "It's Friday"; break; case "6": $url = "<a href= "http://www.saturday.com">Saturday</a>"; $des = "It's Saturday"; break; default: $url = "No URL"; $des = "No description"; } print("$today, $url,$des"); ?> </body> </html> |
|
jennyjlo
|
I think I got it!!!!!
|
|
willie565
|
It Works Perfectly And Only took about 10 minutes to make but noneless I wanted to post it here
|
|
Dest
|
Hi all. i made this one only after look in to other works. i need it only to understand swich function. and i am confused about brackets. but anyway. about switch is clear now :) here's my script:
And working example: http://tts.lt/~sir/scripts/week2.php |
|
CyberAce
|
Helo I just signed up so I am catching up to were I should be. Here is my code for week 2.
[CODE] <? $today = date("w"); $title = "Scriptschool Assignement 2:"; $sunday = "http://www.lvrocks.com"; $monday = "http://www.scriptschool.com"; $tuesday = "http://www.tdscripts.com"; $wednesday = "http://www.theadultwebmaster.com"; $thursday = "http://www.adultnetsurprise.com"; $friday = "http://www.ebay.com"; $saturday = "http://www.cybersorcerer.vzz.net"; ?> <html> <head> <title><? echo $title ?></title> </head> <body> <? switch ($today) { case 0: print("<a href=".$sunday.">".$sunday."</a>"); break; case 1: print("<a href=".$monday.">".$monday."</a>"); break; case 2: print("<a href=".$tuesday.">".$tuesday."</a>"); break; case 3: print("<a href=".$wednesday.">".$wednesday."</a>"); break; case 4: print("<a href=".$thursday.">".$thursday."</a>"); break; case 5: print("<a href=".$friday.">".$friday."</a>"); break; default: print("<a href=".$saturday.">".$saturday."</a>"); } ?> </body> </html> [/CODE] I got it working with just 2 retries. |
|
Ahkorahil
|
<HTML>
<HEAD> <TITLE> MY home assignment 2 </TITLE> </HEAD> <BODY> <?php // This is the switch function to display in each day different URL $today = date("w"); $monlink= "<A HREF = http://www.hot.ee/>"; $mondesc= "hoti kodukas"; $tuelink= "<A HREF =http://www.neti.ee/>"; $tuedesc= "neti lehekülg"; $wednlink= "<A HREF=http://www.jippii.ee/>" ; $wednlink= "jippii!"; $thulink= "<A HREF=http://www.scriptschool.com/>"; $thudesc= "scriptschool"; $frilink= "<A HREF=http://www.zone.ee/kincclan/>" ; $fridesc= "<b> My clan site.</b> Made by me."; $satlink= "<A HREF=http://www.zone.ee/>"; $satdesc= "<b>Zone</b> site"; $sunlink= "<A HREF=http://www.gameland.ee/>" ; $sundesc= "<font face=Monotype Corsiva> Gameland </font>; //SWITCH switch($today) { case 0: print("Today's link is: .$monlink .$monlink"); break; case 1: printf("Today's link is: .$tuelink<br> .$tuedesc"); break case 2: print("Today's link is: .$wednlink<br> .$wedndesc"); case 3: print("Today's link is: .$thulink<br> .$thudesc"); case 4: print("Today's link is: .$frilink<br> .$fridesc"); case 5: printf("today's link is: .$satlink<br> .$satdesc"); default: printf("Today's link is .$sunlink<br> .$sundesc"); } ?> </BODY> </HTML> |
|
coinweb
|
<html>
<head> <TITLE>Homework For Week #2</TITLE> </head> <body bgcolor="blue"> <center><table width="60%" border="1" bgcolor="white"> <br><br><br><br><br><br> <tr> <td> <?php /*TO-DO ASSIGNMENT #2: Write a script to print to the browser a different URL each day of the week using the switch/case statement and comparing to the numeric day of the week (0-6), not the textual (Sunday-Saturday) day of the week. Use only one print() function to do this and make these urls active hyperlinks with the url title hyperlinked and the url description not hyperlinked. Employ the use of concatenation to create the single print function instead of enclosing in interpreted double quotes to demonstrate your understanding of concatenating strings. */ $today =date("w"); $comment = "Please visit this link today:"; //The Switch switch($today) { case "0"; $url = " <a href=\"http://www.ebay.com\">http://www.ebay.com</a><br><br><b>Checkout some auctions this nice quiet Sunday afternoon</b>"; break; case "1"; $url = " <a href=\"http://www.coinwebstore.com/\">http://www.coinwebstore.com</a><br><br><b>Purchase some rare coins to help you get through this manic monday</b>"; break; case "2"; $url = " <a href=\"http://www.google.com/\">http://www.google.com</a><br><br><b>Searching on Tuesdays is never easier than with Google</b>"; break; case "3"; $url = " <a href=\"http://www.humpback.com\">http://www.humpback.com</a><br><br><b>What better place to visit on Wednesday (Hump Day)</b>"; break; case "4"; $url = " <a href=\"http://www.thursday.com\">http://www.thursday.com</a><br><br><b>What more can you say? it's Thursday!</b>"; break; case "5"; $url = " <a href=\"http://www.millerbrewing.com\">http://www.millerbrewing.com</a><br><br><b>Friday Night !! It's Miller time.</b>"; break; case "6"; $url = " <a href=\"http://www.teetool.com\">http://www.teetool.com</a><br><br><b>Need a cool golf tool for your Saturday round?</b>"; break; } print($comment . $url); ?> </td> </tr> </table> </body> </html> |
|
RamblnRick
|
I think this is right. Still trying to get the code to print correctly in the forum. There was mention of a colorize box to be checked that I do not see.
<html> <head> <title>Week Number 2 Basic - Link Of The Day</title> <body>
</body> </html> Working script at http://www.ricksramblings.com/..._assignment.php |
|
RamblnRick
|
The correct URL for the worrking script above is http://www.ricksramblings.com/..._assignment.php |
|
hatiangeek
|
<script language="php">
// This script will out a different active URL based on the day of the week using // the date php function and the switch structure $currentDate=date(w); $Sunday="<a href="http://www.Sakapfet.com">http://www.Sakapfet.com</a>"; $Monday="<a href="http://www.akolad.com">Akolad.com</a>"; $Sunday="<a href="http://www.expresswebsite.com">eXpressWebsite.com</a>"; $Tuesday="<a href="http://www.fouye.com">http://www.fouye.com</a>"; $Wenesday="<a href="http://www.yahoo.com">http://www.yahoo.com</a>"; $Thursday="<a href="http://www.everythinghaitian.com">http://www.everythinghaitian.com</a>"; $Friday="<a href="http://www.haitiexchange.com">http://www.haitiexchange.com.com</a>"; $Saturday="<a href="http://www.baltimoredestmarc.com">http://www.baltimoredestmarc.com</a>"; switch($currentDate) { case 0: print("The site of the day is: ".$Sunday); break; case 1: print("The site of the day is: ".$Monday); break; case 2: print("The site of the day is: ".$Tuesday); break; case 3: print("The site of the day is: ".$Wenesday); break; case 4: print("The site of the day is: ".$Thursday); break; case 5: print("The site of the day is: ".$Friday); break; case 6: print("The site of the day is: ".$Saturday); break; } </script> |
|
DJRemiasz
|
<?
$today = date("l"); if ($today == "Sunday") { print ("<img src=\"\profile.gif\">"); } if ($today == "Friday") { print ("<img src=\"\pencil.gif\">"); } ?> |
|
DJRemiasz
|
Oops! Sorry this is it:
<? $today = date("l"); if ($today == "Sunday") { print ("<img src=\"image0.jpg\">"); } if ($today == "Monday") { print ("<img src=\"image1.jpg\">"); } if ($today == "Tuesday") { print ("<img src=\"image2.jpg\">"); } if ($today == "Wednesday") { print ("<img src=\"image3.jpg\">"); } if ($today == "Thursday") { print ("<img src=\"image4.jpg\">"); } if ($today == "Friday") { print ("<img src=\"image5.jpg\">"); } if ($today == "Saturday") { print ("<img src=\"image6.jpg\">"); } ?> |
|
fudded
|
Note to myself "I must remember ";" ":" " :) |
|
Shannen
|
It seemed like it took forever, but once I got it it was so simple. I used the posts from other people when I was really stuck on syntax, so thanks to everyone who posted.
|
|
TDavid
|
quote: Well done, Shannen, this is the way it works :) Hopefully you can help others if you see someone like Quicksaver has been doing. |
|
Ahkorahil
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> <HEAD> <TITLE> 2. assignment </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <?php //lingid $sunlink ="<a href=http://www.zone.ee>zone</a>"; $monlink ="<a href=http://www.neti.ee>neti</a>"; $tuelink ="<a href=http://www.hot.ee>hot</a>"; $wedlink ="<a href=http://www.delfi.ee>delfi</a>"; $thulink ="<a href=http://www.php.ee>pHp</a>"; $frilink ="<a href=http://www.scriptschool.com>school</a>"; $satlink ="<a href=http://www.zone.ee/eastwestclan>eastwest</a>"; //descriptions $sundes ="zone--- I set my php pages there"; $mondes ="search"; $tuedes ="mail for me"; $weddes ="news!"; $thudes ="estonian php"; $frides ="scriptschool for everyone"; $satdes ="Counterstrike clan"; //today $today =date("l"); switch($today) { case"Sunday": print("$today<br>$sunlink <br> $sundesc"); break; case"Monday": print("$today<br> $monlink <br> $mondes"); break; case"Tuesday": print("$today<br> $tuelink <br> $tuedes"); break; case"Wednesday": print("$today<br> $wedlink <br> $weddes"); break; case"Thursday": print("$today<br> $thulink <br> $thudes"); break; case"Friday": print("$today<br> $frilink <br> $frides"); break; default: print("$today<br> $satlink <br> $satlink"); ?> </BODY> </HTML> ////The line is 54th and I got an error: Parse error: parse error in /www/data03/users/t/test003/new.php3 on line 54 Can You give me any advice |
|
Quicksaver
|
ahkorahil, you didnt close the switch() :)
put an } at the end to close it |
|
logspirit
|
MarcusD79,
I don't usually respond to threads in this course, but I happened to notice that you're having a problem with Your quotes... You must nest Your quotes properly, or use one of the other methods I suggest below... You were breaking out of Your double quote after the
But actually, I don't really think You want to print out either the numerical for the day (0-6) OR the phrase $_today as a word...! Rather I think You would want to print the name of the day such as Tuesday etc... see other examples in this thread above, to see how to do this... Please also see: http://us3.php.net/types.string and: http://www.zend.com/zend/tut/u...ing-strings.php for a fuller discussion of PHP's string syntax. logspirit - author of the MySQL and Javascript courses |
|
logspirit
|
My Last post was really garbled by the code tags... also I didn't realize that this string had gone to two pages and these problems were worked out... at any rate this is what I was attempting to say:
MarcusD79, I don't usually respond to this course, but I happened to notice that you're having a problem with Your quotes... You must nest Your quotes properly... If You start with double quotes the next inner nest uses single quotes, the next inner nest within that single quoted one would be double quoted etc. You were breaking out of Your double quote after the href=" Nor were You concatenating the rest of the string on either (using a . ) So: //Following are values for days $_sun0="$_today s Link is to <a href="http://www.fagfrat.com/photos">Photo Page</a>."; Could be: $_sun0='$_today s Link is to <a href="http://www.fagfrat.com/photos">Photo Page</a>.'; Please notice the single quotes in the outer string and then double quotes in the inner nest... using single quotes is faster for PHP and should always be used preferentially UNLESS You are auto parsing variables within the string - which requires double quotes and is slower (to check for, and parse existing variables within the string)! Note that single quoting results in LITERAL interpretations! Another alternative would be to slash out the inner double quotes AND Your variable's $ sign, so that PHP doesn't try to parse it as a variable! Which it can't do in this instance anyway, since $_today is an ARRAY which has not had it's inner location specified. Slashing out the quotes and variables allows them to be printed out as LITERALS without affecting the functionality of Your script.: $_sun0="\$_today s Link is to <a href=\"http://www.fagfrat.com/photos\">Photo Page</a>."; But actually, I don't really think You want to print out either the numerical for the day (0-6) OR the phrase $_today as a word...! Rather I think You would want to print the name of the day such as Tuesday etc... see other examples in this thread above, to see how to do this... Please also see: http://us3.php.net/types.string and http://www.zend.com/zend/tut/u...ing-strings.php for a fuller discussion of PHP's string syntax. logspirit - author of the MySQL and Javascript courses |
|
TylerTT
|
|
|
n2o2k
|
|
|
PureGrain
|
The reason for extra writing in the heading is due to me posting my success on a web site that I am putting together for my referance. Hope this is right! Crosses Fingers!! |
|
PureGrain
|
I was just tinkering with the other parts of the lessons, like the diff pic for every day of the week. Which i was ablr to get to work. Then after completing the assignment, I decided to go back and do the Escape from PHP to output HTML. I cannot seem to get this to work. Can you look at the code and tell me where I went wrong?
Thanks in advance. |
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