943,828 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1386
  • PHP RSS
Mar 14th, 2007
0

Need to Sum up this code

Expand Post »
Here is my code I need help with:
mysql_connect($host,$username,$password);

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



$query = "SELECT DISTINCT info647_crse . crsdesc , info647_crse . crsprice FROM info647_emp JOIN info647_reg USING ( empno ) JOIN info647_off USING ( offerno ) JOIN info647_crse USING ( crsno ) WHERE empno = '$empno' LIMIT 0, 30 ";
$result=mysql_query($query);

$num=mysql_numrows($result);




mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;



while ($i < $num) {





$desc=mysql_result($result,$i,"crsdesc");

$crsprice=mysql_result($result,$i,"crsprice");






echo "<br>Class: $desc<br>Price: $crsprice<br><br><hr><br>";

$i++;

}

echo("Total Price of Classes for employee $empno :");
echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Employee Queried</font></p>");
include("footer.html");

?>

It outputs like this:

Class: SEARCHES 102
Price: 300.01




Class: FIREARMS 102
Price: 200.02



Total Price of Classes for employee 1006 :
Employee Queried
Close

What I want to do is add up the Prices and put it after the : part can anyone help me? This is for my info647 class.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Mar 15th, 2007
0

Re: Need to Sum up this code

$crsprice1=$crsprice1+$crsprice

and then print the $crsprice1
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Mar 15th, 2007
0

Re: Need to Sum up this code

I am not sure I understand where to put that in the code. This is what I did and it didn't work. Thank you in advance for the help.
while ($i < $num) {





$desc=mysql_result($result,$i,"crsdesc");

$crsprice=mysql_result($result,$i,"crsprice");






echo "<br>Class: $desc<br>Price: $crsprice<br><br><hr><br>";

$i++;

}
$crsprice1=$crsprice1+$crsprice
echo("Total Price of Classes for employee# $empno ");
echo ("$crsprice1");
echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Employee Queried</font></p>");

include("footer.html");

?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Mar 15th, 2007
0

Re: Need to Sum up this code

This is why people need to post their codes. I am such a dork! I forgot the semicolon on my code. It works now. Thanks for your help I really appreciate it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help (again) on a modify record script
Next Thread in PHP Forum Timeline: Symfony + skipping actions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC