php help.
Ok so when they select a number between 1-8 on the previous page before this one they select how many different <option></option> 's they get between the select tag. Like if it syas case "2" they get two <option> tags being echo'd on the page. Sadly this is not working and says i have a problem at line 15 where it has the first "echo "<select>…." Can someone hlep me… i really need to figure this out
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head>
<body> <form method="get" action="calculator.php"> <?php switch($number)
{ case "1"; echo "<select><option name="grade1" value="4">A</option> <option name="grade1" value="3">B</option> <option name="grade1" value="2">C</option> <option name="grade1" value="1">D</option> <option name="grade1" value="0">F</option> </select>"; break;
case "2";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>";
break;
case "3";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>";
break;
case "4";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>
<select><option name="grade4" value="4">A</option>
<option name="grade4" value="3">B</option>
<option name="grade4" value="2">C</option>
<option name="grade4" value="1">D</option>
<option name="grade4" value="0">F</option>
</select>";
break;
case "5";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>
<select><option name="grade4" value="4">A</option>
<option name="grade4" value="3">B</option>
<option name="grade4" value="2">C</option>
<option name="grade4" value="1">D</option>
<option name="grade4" value="0">F</option>
</select>
<select><option name="grade5" value="4">A</option>
<option name="grade5" value="3">B</option>
<option name="grade5" value="2">C</option>
<option name="grade5" value="1">D</option>
<option name="grade5" value="0">F</option>
</select>";
break;
case "6";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>
<select><option name="grade4" value="4">A</option>
<option name="grade4" value="3">B</option>
<option name="grade4" value="2">C</option>
<option name="grade4" value="1">D</option>
<option name="grade4" value="0">F</option>
</select>
<select><option name="grade5" value="4">A</option>
<option name="grade5" value="3">B</option>
<option name="grade5" value="2">C</option>
<option name="grade5" value="1">D</option>
<option name="grade5" value="0">F</option>
</select>
<select><option name="grade6" value="4">A</option>
<option name="grade6" value="3">B</option>
<option name="grade6" value="2">C</option>
<option name="grade6" value="1">D</option>
<option name="grade6" value="0">F</option>
</select>";
break;
case "7";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>
<select><option name="grade4" value="4">A</option>
<option name="grade4" value="3">B</option>
<option name="grade4" value="2">C</option>
<option name="grade4" value="1">D</option>
<option name="grade4" value="0">F</option>
</select>
<select><option name="grade5" value="4">A</option>
<option name="grade5" value="3">B</option>
<option name="grade5" value="2">C</option>
<option name="grade5" value="1">D</option>
<option name="grade5" value="0">F</option>
</select>
<select><option name="grade6" value="4">A</option>
<option name="grade6" value="3">B</option>
<option name="grade6" value="2">C</option>
<option name="grade6" value="1">D</option>
<option name="grade6" value="0">F</option>
</select>
<select><option name="grade7" value="4">A</option>
<option name="grade7" value="3">B</option>
<option name="grade7" value="2">C</option>
<option name="grade7" value="1">D</option>
<option name="grade7" value="0">F</option>
</select>";
break;
case "8";
echo "<select><option name="grade1" value="4">A</option>
<option name="grade1" value="3">B</option>
<option name="grade1" value="2">C</option>
<option name="grade1" value="1">D</option>
<option name="grade1" value="0">F</option>
</select>
<select><option name="grade2" value="4">A</option>
<option name="grade2" value="3">B</option>
<option name="grade2" value="2">C</option>
<option name="grade2" value="1">D</option>
<option name="grade2" value="0">F</option>
</select>
<select><option name="grade3" value="4">A</option>
<option name="grade3" value="3">B</option>
<option name="grade3" value="2">C</option>
<option name="grade3" value="1">D</option>
<option name="grade3" value="0">F</option>
</select>
<select><option name="grade4" value="4">A</option>
<option name="grade4" value="3">B</option>
<option name="grade4" value="2">C</option>
<option name="grade4" value="1">D</option>
<option name="grade4" value="0">F</option>
</select>
<select><option name="grade5" value="4">A</option>
<option name="grade5" value="3">B</option>
<option name="grade5" value="2">C</option>
<option name="grade5" value="1">D</option>
<option name="grade5" value="0">F</option>
</select>
<select><option name="grade6" value="4">A</option>
<option name="grade6" value="3">B</option>
<option name="grade6" value="2">C</option>
<option name="grade6" value="1">D</option>
<option name="grade6" value="0">F</option>
</select>
<select><option name="grade7" value="4">A</option>
<option name="grade7" value="3">B</option>
<option name="grade7" value="2">C</option>
<option name="grade7" value="1">D</option>
<option name="grade7" value="0">F</option>
</select>
<select><option name="grade8" value="4">A</option>
<option name="grade8" value="3">B</option>
<option name="grade8" value="2">C</option>
<option name="grade8" value="1">D</option>
<option name="grade8" value="0">F</option>
</select>";
break;
default:
echo ("Go back and do it again");
?> </form> </body> </html>
darthchocobo wrote: What do you mean use a back slash?
When you echo double quotes, you need a backslash to escape it (prevent it from ending the echo)
echo "<a href=\"php.php\">PHP</a>";
?>```
Is actually:
```markup<?php
echo "<a href="php.php">PHP</a>";
?>```
But, what would happen if you didn't use the backslashes? The echo would be cut off when the next double quote (unescaped) was used, and 'php.php' with the rest of the line would just return a syntax error.
Refer to the PHP Manual for strings:
http://au2.php.net/types.string
You can also change those echo statements to single quoted (') strings, then you dont have to worry about problems with using double quotes (") in your output.
Obviously, there's a difference between using ' and ", so I suggest you read up on whichever is most appropriate for what you're trying to do.
darthchocobo wrote: If i were to put single quotes around echo '….' then it would be all fine? But what if inside i have a value for osmething such as <option name="blah" value="vlah"></option> do i use double quotes or will i have to put the name="\blah"?
From what you posted above using single quotes would be fine, you wouldn't have to change anything else. (ie, leave the double quotes inside the tags as they are)
Using ' is different to " though. One difference is that you cannot do variable expansion in single quoted strings. You dont have any variables in your echo statements, which is why I suggest using a single quoted string.
Read the PHP manual on strings if you're still unsure.
Johnson wrote: Refer to the PHP Manual for strings:
http://au2.php.net/types.string
You can also change those echo statements to single quoted (') strings, then you dont have to worry about problems with using double quotes (") in your output.
Obviously, there's a difference between using ' and ", so I suggest you read up on whichever is most appropriate for what you're trying to do.
For one double quotes parse variables whereas single quotes don't.
Ok so i fixed that problem and now it has an issue with line 316 which is the very last line. what could that mean?
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> <title>Untitled Document</title> </head>
<body> <form method='get' action='calculator.php'> <?php switch($number)
{ case "1": echo "<select><option name='grade1' value='4'>A</option> <option name='grade1' value='3'>B</option> <option name='grade1' value='2'>C</option> <option name='grade1' value='1'>D</option> <option name='grade1' value='0'>F</option> </select>"; break;
case "2":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>";
break;
case "3":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>";
break;
case "4":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>
<select><option name='grade4' value='4'>A</option>
<option name='grade4' value='3'>B</option>
<option name='grade4' value='2'>C</option>
<option name='grade4' value='1'>D</option>
<option name='grade4' value='0'>F</option>
</select>";
break;
case "5":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>
<select><option name='grade4' value='4'>A</option>
<option name='grade4' value='3'>B</option>
<option name='grade4' value='2'>C</option>
<option name='grade4' value='1'>D</option>
<option name='grade4' value='0'>F</option>
</select>
<select><option name='grade5' value='4'>A</option>
<option name='grade5' value='3'>B</option>
<option name='grade5' value='2'>C</option>
<option name='grade5' value='1'>D</option>
<option name='grade5' value='0'>F</option>
</select>";
break;
case "6":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>
<select><option name='grade4' value='4'>A</option>
<option name='grade4' value='3'>B</option>
<option name='grade4' value='2'>C</option>
<option name='grade4' value='1'>D</option>
<option name='grade4' value='0'>F</option>
</select>
<select><option name='grade5' value='4'>A</option>
<option name='grade5' value='3'>B</option>
<option name='grade5' value='2'>C</option>
<option name='grade5' value='1'>D</option>
<option name='grade5' value='0'>F</option>
</select>
<select><option name='grade6' value='4'>A</option>
<option name='grade6' value='3'>B</option>
<option name='grade6' value='2'>C</option>
<option name='grade6' value='1'>D</option>
<option name='grade6' value='0'>F</option>
</select>";
break;
case "7":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>
<select><option name='grade4' value='4'>A</option>
<option name='grade4' value='3'>B</option>
<option name='grade4' value='2'>C</option>
<option name='grade4' value='1'>D</option>
<option name='grade4' value='0'>F</option>
</select>
<select><option name='grade5' value='4'>A</option>
<option name='grade5' value='3'>B</option>
<option name='grade5' value='2'>C</option>
<option name='grade5' value='1'>D</option>
<option name='grade5' value='0'>F</option>
</select>
<select><option name='grade6' value='4'>A</option>
<option name='grade6' value='3'>B</option>
<option name='grade6' value='2'>C</option>
<option name='grade6' value='1'>D</option>
<option name='grade6' value='0'>F</option>
</select>
<select><option name='grade7' value='4'>A</option>
<option name='grade7' value='3'>B</option>
<option name='grade7' value='2'>C</option>
<option name='grade7' value='1'>D</option>
<option name='grade7' value='0'>F</option>
</select>";
break;
case "8":
echo "<select><option name='grade1' value='4'>A</option>
<option name='grade1' value='3'>B</option>
<option name='grade1' value='2'>C</option>
<option name='grade1' value='1'>D</option>
<option name='grade1' value='0'>F</option>
</select>
<select><option name='grade2' value='4'>A</option>
<option name='grade2' value='3'>B</option>
<option name='grade2' value='2'>C</option>
<option name='grade2' value='1'>D</option>
<option name='grade2' value='0'>F</option>
</select>
<select><option name='grade3' value='4'>A</option>
<option name='grade3' value='3'>B</option>
<option name='grade3' value='2'>C</option>
<option name='grade3' value='1'>D</option>
<option name='grade3' value='0'>F</option>
</select>
<select><option name='grade4' value='4'>A</option>
<option name='grade4' value='3'>B</option>
<option name='grade4' value='2'>C</option>
<option name='grade4' value='1'>D</option>
<option name='grade4' value='0'>F</option>
</select>
<select><option name='grade5' value='4'>A</option>
<option name='grade5' value='3'>B</option>
<option name='grade5' value='2'>C</option>
<option name='grade5' value='1'>D</option>
<option name='grade5' value='0'>F</option>
</select>
<select><option name='grade6' value='4'>A</option>
<option name='grade6' value='3'>B</option>
<option name='grade6' value='2'>C</option>
<option name='grade6' value='1'>D</option>
<option name='grade6' value='0'>F</option>
</select>
<select><option name='grade7' value='4'>A</option>
<option name='grade7' value='3'>B</option>
<option name='grade7' value='2'>C</option>
<option name='grade7' value='1'>D</option>
<option name='grade7' value='0'>F</option>
</select>
<select><option name='grade8' value='4'>A</option>
<option name='grade8' value='3'>B</option>
<option name='grade8' value='2'>C</option>
<option name='grade8' value='1'>D</option>
<option name='grade8' value='0'>F</option>
</select>";
break;
default:
echo "Go back and do it again";
?> </form> </body> </html>