Here is my code I need help with:

mysql_connect[B]($host,$username,$password);[/B]

[B]@[/B]mysql_select_db[B]($database)[/B] [B]or[/B] die[B]([/B] "Unable to select database"[B]);[/B]



[B]$query[/B] [B]=[/B] "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 "[B];[/B]
[B]$result=[/B]mysql_query[B]($query);[/B]

[B]$num=[/B]mysql_numrows[B]($result);[/B]




mysql_close[B]();[/B]

echo "<b><center>Database Output</center></b><br><br>"[B];[/B]

[B]$i=[/B]0[B];[/B]



[B]while[/B] [B]($i[/B] < $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.

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.

[B]while[/B] [B]($i[/B] < $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");

?>

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.

This article has been dead for over six months. Start a new discussion instead.