I am trying to figure out how to do tables in php. I am working on this..

$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$bar=.55;
echo "Starting balance:$balance";
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance+$earn;
echo "<p>ATM Deposit:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance/2;
echo "<p>Balance after split with wife:".sprintf("$%.2f",$balance)."</p>"

This is suppose to be display in a table. I am a newbie at php I am not looking for the answers just someone to explain to me how it is possible i know the table format which is

<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

But I just dont understand how to put the two together.

Hello friend,
You dont need to confuse.
U just add HTML coding in ur php by using echo. Need to care about "" and '.

Below i showed the codes(' ,"")difference for HTML and PHP
HTML coding <table border="1">
php coding echo "<table border='1'>";

i just give a small example.

<?
$data1="first";
$data1_val1="1";

$data2="first";
$data2_val2="1";

$data3="first";
$data3_val3="1";

echo "<TABLE><TR><TH>Number in abbr</TH><TH>Number in symbol</TH></TR>";

echo "<TR> <TD>$data1</TD><TD>$data1_val1</TD> </TR>";
echo "<TR> <TD>$data2</TD><TD>$data1_val2</TD> </TR>";
echo "<TR> <TD>$data3</TD><TD>$data1_val3</TD> </TR>";

echo "</TABLE>";

It looks harder then it seems cause I am still confused? Do you know any good website to help explain this?

I dont know reg the website... U may use google... Sorry...

I just dont know why It is so hard for me to understand this. I know how to use html table and I am trying to mix the both together but I am thinking I am not wording it right.This is what I have so far but it is not working.

<? php

<body>
	<h1>Balance</h1>

$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$bar=.55;


<TABLE border="1">

 <tr>"Starting balance:$balance";</tr>
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance+$earn;
echo "<p>ATM Deposit:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance/2;
echo "<p>Balance after split with wife:".sprintf("$%.2f",$balance)."</p>"
</TABLE>
?>
</body>
</html>

<? php
/* Shuawna Norris
June 13, 2011
Part two
Working with money
*/
echo “<body>”;
echo ” <h1>Balance</h1>”;

$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$bar=.55;
echo ”<TABLE border=’1’>”;

echo “<tr>"Starting balance:$balance";</tr>”;
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance+$earn;
echo "<p>ATM Deposit:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance/2;
echo "<p>Balance after split with wife:".sprintf("$%.2f",$balance)."</p>"
echo “</TABLE>”;
?>
</body>
</html>

You can escape HTML from the PHP delimiter and echo the value in their specific '<td>'. Example below:

<? php
/* Shuawna Norris
June 13, 2011
Part two
Working with money
*/

$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$bar=.55;
?>
<body>
<h1>Balance</h1>
<TABLE border=’1’>”;
<tr><td colspan="3">Starting balancebalance</td></tr>
<tr>
<td>Purchase: Clothing Store:<?php echo sprintf("$%2f", ($balance-$newShirtCost)); ?></td>
<td>ATM Deposit: <?php echo sprintf("$%2f", ($balance+$earn)); ?></td>
<td>Balance after split with wife: <?php echo sprintf("$%.2f", ($balance/2)); ?></td>
</tr>
</table>
</body>

This is more readable and easy to maintain.

commented: helpful +4

<? php
/* Shuawna Norris
June 13, 2011
Part two
Working with money
*/
echo “<body>”;
echo ” <h1>Balance</h1>”;

$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$bar=.55;
echo ”<TABLE border=’1’>”;

echo “<tr>"Starting balance:$balance";</tr>”;
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance+$earn;
echo "<p>ATM Deposit:".sprintf("$%.2f",$balance)."</p>";
$balance=$balance/2;
echo "<p>Balance after split with wife:".sprintf("$%.2f",$balance)."</p>"
echo “</TABLE>”;
?>
</body>
</html>

Please use code tags to post your code.

OK from what i see should i be doing two pages or just one?

<?php
	$balance=55.75;
    $newShirtCost=15.75;
    $earns=20.00;
    $bar=.55;
?>
<!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>
    <h1>Balance</h1>
     
    
     
     
    <TABLE border="1">
     	<tr><td>Starting balance</td><td><?php echo $balance; ?> </td></tr>
        <tr>
        	<td>Purchase: Clothing Store</td>
            <td>
				<?php
                    $balance= $balance -$newShirtCost;
                    echo sprintf("$%.2f",$balance);
                ?>
        	</td>
        </tr>
        <tr>
        	<td>ATM Deposit</td>
        	<td>
				<?php
                    $balance=$balance+$earn;
                    echo sprintf("$%.2f",$balance);
                ?>
       		</td></tr>
        <tr>
        	<td>Balance after split with wife</td>
            <td>
        		<?php
					$balance=$balance/2;
					echo sprintf("$%.2f",$balance);
				?>
        	</td>
       	</tr>
    </TABLE>
    
    </body>
    </html></html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.