Page 1 of 1

Maths functions

Posted: Tue Mar 17, 2009 8:39 am
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

Re: Maths functions

Posted: Tue Mar 17, 2009 9:46 am
by pickle
You're subtracting some html code from some other html code. String math doesn't work so well.

Re: Maths functions

Posted: Tue Mar 17, 2009 10:17 am
by nishmgopal
any suggestions?

Re: Maths functions

Posted: Tue Mar 17, 2009 10:33 am
by a.heresey
Are you trying to subtract the weight from the score?

Why not use:

Code: Select all

$diff = $row['Score']-$row['Weight'];

Re: Maths functions

Posted: Tue Mar 17, 2009 10:40 am
by nishmgopal
Yeh i already tried that and i get a return of 0