解析url中的变量,但也更改单元格填充、边框和背景



所以我正在使用解析变量创建一个计算器。无论我在url中还是在表单中输入变量的值,页面都应该进行计算。现在x,y,z工作得很好,但我也需要对单元格填充、边框和背景颜色做同样的处理。当用户为表赋值时,我如何使用解析变量来更改表的实际填充、边框和bckgrd颜色?请帮忙!非常感谢!

<?php
// parse variables from URLs
echo "This is the value of <b>x:</b>  " . $_GET['x'] . ". This is the value of <b>y: </b> " . $_GET['y'] . ".This is the value of <b>z: </b>  " . $_GET['z'] . " , And the title is: " . $_GET['title'] . ".";
?>
<?
$x = $_GET['x'];
$y = $_GET['y'];
$z = $_GET['z'];
$result1 = $x + $y - 2*$z;
$result2 = 2*$x + 4*$y + (3*$z - 80);
$result3 = $result1 + $result2; 
$pad = $_GET['pad'];
$brdr = $_GET['brdr'];
$bckrd = $_GET['bckrd'];
?>
<center><h2> Math </h2></center>
<center> <table  cellpadding=20  border= 5  bgcolor= #FFFFFF>
        <tr>
            <td><b>Mathematical Operation</b></td>
            <td><b>Result</b></td>  
        </tr>
        <tr>
            <td>x + y - 2 * z</td>
            <td><?echo "$result1";?>
            </td>
        </tr>
        <tr>
            <td>2x - 4y + (3z - 80)</td>
            <td><?echo "$result2";?>
            </td>
        </tr>
        <tr>
            <td>Row2 - Col2 + result of Row3 - Col2</td>
            <td><?echo "$result3";?>
            </td>
        </tr>
    </table> 
    </center>

<form>
<u>Inputs:</u> <br />
X-value <input type="text" name="x" value=""></input><br />
Y-Value <input type="text" name="y" value=""></input><br />
Z-Value <input type="text" name="z" value=""></input><br />
Title <input type="text" name="title" value=""></input><br />
Table Padding <input type="text" name="pad" value=""></input><br />
Table Border <input type="text" name="brdr" value=""></input><br />
Background Color <input type="color" name="bckrd" value=""></input><br />
<input type="submit" name="submit" value="SUBMIT and CALCULATE"></input>
</form>
<?
if ($_GET['submit']) {  
    $result1 = $x + $y - 2*$z;
    $result2 = 2*$x + 4*$y + (3*$z - 80);
    $result3 = $result1 + $result2;     
    }
?>      

您应该使用它来在html:中使用PHP变量

$pad = (isset($_GET['pad'])) ? $_GET['pad'] : 20;
$brdr = (isset($_GET['brdr'])) ? $_GET['brdr'] : 5;
$bckrd = (isset($_GET['bckrd'])) ? $_GET['bckrd'] : "#FFFFFF";
echo "<center><h2> Math </h2></center>";
echo "<center> <table  cellpadding=".$pad." border=".$brdr." bgcolor=".$bckrd.">";
?>
<tr>
    <td><b>Mathematical Operation</b></td>
    <td><b>Result</b></td>  
</tr>

相关内容

  • 没有找到相关文章

最新更新