Maths functions

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
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Maths functions

Post by nishmgopal »

Hi guys, this is my code:

Code: Select all

$query1="SELECT `Skill_Name`, `Weight`
        FROM ID_Table
        JOIN Job_ID ON ID_Table.Job_ID = Job_ID.Job_ID
        WHERE Job_ID.Job_Name ='$_SESSION[Job_Name]'";
 
$result1 = mysql_query($query1) or die ("Couldn't execute query.");
 
while ($row1=mysql_fetch_array($result1))
{
    $tblRows1 .= "<tr>";
    $tblRows1 .= "<td>{$row1['Skill_Name']}</td>";
    $tblRows1 .= "<td>{$row1['Weight']}</td>";
    $tblRows1 .= "</tr>\n";
    
    
}
 
$query="SELECT `Skill_Name`, `Score`
        FROM Person_Skill
        JOIN Person_ID ON Person_Skill.Person_ID = Person_ID.Person_ID
        WHERE Person_ID.Person_Name ='$_SESSION[Person_Name]'";
 
$result = mysql_query($query) or die ("Couldn't execute query.");
 
while ($row=mysql_fetch_array($result))
{
    $tblRows .= "<tr>";
    $tblRows .= "<td>{$row['Skill_Name']}</td>";
    $tblRows .= "<td>{$row['Score']}</td>";
    $tblRows .= "</tr>\n";
}
 
 
 
 
$diff=($tblRows - $tblRows1);
 
echo "$diff";
 
?>
but the above code just returns a 0....do i need to use a loop of some sort to get all the differences?

thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Maths functions

Post by pickle »

You're subtracting some html code from some other html code. String math doesn't work so well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Maths functions

Post by nishmgopal »

any suggestions?
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: Maths functions

Post by a.heresey »

Are you trying to subtract the weight from the score?

Why not use:

Code: Select all

$diff = $row['Score']-$row['Weight'];
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Maths functions

Post by nishmgopal »

Yeh i already tried that and i get a return of 0
Post Reply