954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP and tables

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.

sha1023012
Light Poster
30 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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
php coding echo "";

i just give a small example.

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

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

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

echo "Number in abbrNumber in symbol";

echo "$data1$data1_val1 ";
echo "$data2$data1_val2 ";
echo "$data3$data1_val3 ";

echo "";

reksss
Newbie Poster
6 posts since Jun 2011
Reputation Points: 10
Solved Threads: 2
 

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

sha1023012
Light Poster
30 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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

reksss
Newbie Poster
6 posts since Jun 2011
Reputation Points: 10
Solved Threads: 2
 

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>
sha1023012
Light Poster
30 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

”;
echo ” Balance”;

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

echo “"Starting balance:$balance";”;
$balance= $balance -$newShirtCost;
echo "Purchase: Clothing Store:".sprintf("$%.2f",$balance)."


";
$balance=$balance+$earn;
echo "ATM Deposit:".sprintf("$%.2f",$balance)."


";
$balance=$balance/2;
echo "Balance after split with wife:".sprintf("$%.2f",$balance)."


"
echo “”;
?>

reksss
Newbie Poster
6 posts since Jun 2011
Reputation Points: 10
Solved Threads: 2
 

You can escape HTML from the PHP delimiter and echo the value in their specific ''. 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.

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

”;
echo ” Balance”;

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

echo “"Starting balance:$balance";”;
$balance= $balance -$newShirtCost;
echo "Purchase: Clothing Store:".sprintf("$%.2f",$balance)."


";
$balance=$balance+$earn;
echo "ATM Deposit:".sprintf("$%.2f",$balance)."


";
$balance=$balance/2;
echo "Balance after split with wife:".sprintf("$%.2f",$balance)."


"
echo “”;
?>

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

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

sha1023012
Light Poster
30 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 
<?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>
Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: