Question: Hello! So I have an assignment that I'm stuck on for a PHP class. We have to create tables with HTML and PHP. Here's the
Hello! So I have an assignment that I'm stuck on for a PHP class. We have to create tables with HTML and PHP. Here's the assignment:
Exercise 2
Implement a PHP script that creates (12) HTML tables outlining examples of data types and operators like shown in the table below (see the PHP script under the Reading section for some guidance) : 
- float subtraction
- integer division
- integer modulus
- integer equal
- string equal
- float not equal
- integer greater than
- string concatenation
- boolean and
- boolean or Those 10 items are all the items we are to have inside the tables. The script my professor is referring to is this:
table, th, td { border: 1px solid black; }
.header{ background-color: rgb(207, 212, 197); }
.data{ background-color: rgb(230, 173, 236); }
// example of HTML table using echo over multiple lines echo "table showing how to use + with integers";
echo "
| variable \$x | variable \$y | addition (+) | |
| integer | $x | $y | $res |
"; // reassign values to variables $x = 2.5; $y = 5.33; $res = $x + $y;
// example of HTML using print() instead of echo print("table showing how to use + with float");
print("
| "); print(" | variable \$x | "); print("variable \$y | "); print("addition (+) | "); print("
| float | "); print("$x | "); print("$y | "); print("$res | "); print("
");
?> So far, I have:
I used the format of the code I have above that image, that our professor gave us. I changed the float variables into integers properly for tables 3-6. My issue is that 1. my answers are printing as 1 or 0 for true or false: is there a way to fix this that ISN'T a if else statement? Or, if I do have to use an if else statement, is there a way to put that into the tables the way that code I posted allows? Normally, when my professor gives a snippet of code like that it's because that's how he wants us to fulfill the assignment. I also can't get the equals (==) to print. The way my code is currently I have $a = 45, $b = -3, and $answer = $a == $b. inside the echo code that has all the html inside it, as opposed to the other one which individually prints each part of the table. OR is that one the best way to code this assignment? I'm just at a loss. Thanks so much for any help!
table showing how to use + with integers variable $x variable $y addition (+) integer 7 15 12 Result of $x+$y table showing how to use + with float variable $x variable $y addition (+) float 2.5 5.33 7.83 Value of $y The folloing tables will show different operations with Float numbers Table showing subtraction: variable $a variable $b subtraction float 60.75 3.25 57.5 Table showing not equal variable $a variable $b not equal (!=) float 60.75 1 3.25 The folloing tables will show different operations with Intiger numbers Table showing division variable $a variable $b division ( integer 45 -3 -15 Table showing modulus variable $a variable $b modulus (%) integer 45 -3 0 Table showing equals ; variable $a variable $b equals integer 45 1-3 Table showing greater than ; variable $a variable $b greater than > integer 45 -3 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
