cost keeper

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jdd
Forum Newbie
Posts: 1
Joined: Thu Nov 09, 2006 2:51 pm

cost keeper

Post by jdd »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,  I am working on a contact mangement script the script itself works, however I want to add to it.  My boss wants to keep track of the cost for each apartment he owns indivually.  The way this script displays value is veritically in a table using a loop. 

Date, Apartment, Purchases, Repairs, Cost, SubletLabor, SubletCost, Total Cost, Overall Apt Cost
Date, Apartment, Purchases, Repairs, Cost, SubletLabor, SubletCost, Total Cost, Overall Apt Cost
Date, Apartment, Purchases, Repairs, Cost, SubletLabor, SubletCost, Total Cost, Overall Apt Cost
Date, Apartment, Purchases, Repairs, Cost, SubletLabor, SubletCost, Total Cost, Overall Apt Cost

Each entrie is listed like so, Im trying to  get Overall Apt Cost to show each entry for lets say Apt 1 to update how much was spent on just that apartment.  

2006-01-10, 42 Brunswick St Ap1, Pipe Fittings, Fixed Tub, $40.00, NA, NA, ([b]FIELD Im trying to calculate[/b]) 
2006-02-09, 42 Brunswick St Ap1, Paint, Painted Bedroom, $65.00, NA, NA, ([b]FIELD Im trying to calculate[/b])

Trying to add the $totalcost fields up to show in the $Overallcost  field. Someone suggested a new sql statement line. Heres the script.  This links to another .php page with a Forum and updates the database through a third .php page.   Any help greatly appreciated.

Code: Select all

<?
$User="something";
$password="somethingpass";
$database="tim";
$table="timtable";

$link = mysql_connect('localhost', $user, $password);
 if (!$link) {
    die('Could not connect: ' . mysql_error());
 }


// echo 'Connected successfully';

@mysql_select_db($database) or die( "Unable to select database");


// echo 'Connected successfully';


$sql = "SELECT * FROM $table";

$result=mysql_query($sql);
$num=mysql_numrows($result);
mysql_close();


echo "<TABLE BORDER=1><TR BGCOLOR=green><TD><FONT SIZE=2>Modify</FONT></TD><TD><FONT SIZE=2>Building</FONT></TD><TD><FONT SIZE=2>Date</FONT></TD><TD><FONT SIZE=2>Purchases</FONT></TD><TD><FONT SIZE=2>Repairs</FONT></TD><TD><FONT SIZE=2>Cost</FONT></TD><TD><FONT SIZE=2>Sublet Labor</FONT></TD><td><FONT SIZE=2>Sublet Cost</FONT></td><td><FONT SIZE=2>Total Cost</FONT></td></TR>";

$i=0;

while ($i < $num) {


if ($i % 2) {
$color='#cccccc';
}else{
$color='#eeeeee';
}


$id=mysql_result($result,$i,"id");
$d1=mysql_result($result,$i,"building");
$d2=mysql_result($result,$i,"idate");
$d3=mysql_result($result,$i,"purchase");
$d4=mysql_result($result,$i,"repair");
$d5=mysql_result($result,$i,"cost");
$d6=mysql_result($result,$i,"subletlabor");
$d7=mysql_result($result,$i,"subletcost");

$totalcost=($d5+$d7);
echo "<TR BGCOLOR=$color><TD><A HREF=edit.php?id=$id><FONT SIZE=1>EDIT | <a href=delete.php?id=$id>Delete</a></FONT></A></TD><TD><FONT SIZE=1>$d1</FONT></TD><TD><FONT SIZE=1>$d2</FONT></TD><TD><FONT SIZE=1>$d3</FONT></TD><TD><FONT SIZE=1>$d4</FONT></TD><TD><FONT SIZE=1>$ $d5</FONT></TD><TD><FONT SIZE=1>$d6</FONT></TD><TD><FONT SIZE=1>$ $d7</FONT></td><td><FONT SIZE=1>$ $totalcost</FONT></td></TR>";

$i++;



}

echo "</TABLE><A HREF=menu.html>Return to Menu</A>";

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply