/    Sign up×
Community /Pin to ProfileBookmark

adding fields together

I’m trying to change a working program to add three fields (rentdue+prevbal+ misc=balance) together. Can this be done with PHP or do I need Javascript?

[ICODE]<?php?>
<HTML>
<HEAD>
<script type=”text/javascript”>
var monthNames = [ “January”,”February”,”March”,”April”,”May”,”June”,”July”,
“August”,”September”,”October”,”November”,”December” ];
var today = new Date();

var mmyy = monthNames[today.getMonth()] + “/” + today.getFullYear();
</script>
</HEAD>
<BODY><center>
<font size=+2><b>Hammock Oaks Apartments</font><br><br></center>
Rent Receipt……………..for………………….
</head>
<body>
<script type=”text/javascript”>document.write(mmyy);</script>
</script>
<?
mysql_connect(localhost,root,””);
mysql_select_db(prerentdb) or die( “Unable to select database”);
if(!empty($_POST[“submit”]))
{

$apt = $_POST[‘apt’];
$query=”SELECT name, apt, amtpaid, rentdue, prevbal, misc, datepaid FROM payments Where apt=’$apt'”;
$result=mysql_query($query);
if(mysql_num_rows($result))
{
echo “<form action=’#’ method=’post’><font size=4><b></font>&nbsp;&nbsp;&nbsp;<br /><br /><i>amount

paid is the total paid this month<br /><br /></i>
<table border=’0′>
<tr>
<th>.</th>
</tr>”;
echo “</table>”;
echo “</form>”;
while(list($name,$apt,$amtpaid,$rentdue,$prevbal,$misc,$datepaid)= mysql_fetch_row($result))
{
echo “$name , in apartment $apt has paid $ $amtpaid of the $ $balance owed on this day $datepaid<br />”;
}

}
else{echo “No listing for appartment $apt.<br />Please select another.<br />”;}
}
?>
<form method=”post” action=”#”>
<br />
<input type=”text” name=”apt”/> <p>
<input type=”submit” name=”submit” value=”receipt apartment”/>
</form>[/ICODE]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindOct 17.2010 — as long as $rentdue, $prevbalance and $misc are all integers, then yes. It's just like any other variable.

[code=php]
$balance = $rentdue+$prevbalance+$misc;
[/code]


Also, your date stuff at the top can be simplified into a single line of PHP:

[code=php] $mmyy = date("n/y");
// $mmyy = 10/10[/code]
Copy linkTweet thisAlerts:
@DasherOct 17.2010 — Your could also do it in your query

SELECT (rentdue + prevbal + misc) AS balance FROM payments WHERE .....

Adding does not require the fields to be integers, they just need to be numeric.
Copy linkTweet thisAlerts:
@ckdoublenecksauthorOct 17.2010 — thanks guys
×

Success!

Help @ckdoublenecks spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...