Jump to content

Comparing Values from Different tables


nishmgopal

Recommended Posts

Hi Guys,

 

I have two table, and one of the table there is a field called Score and the other one has a field called Weight.

 

I want to compare the two and display a name only if score is = or > weight.

 

my code is below:

 

$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";
}

$query="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]}'";

$result = mysql_query($query) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result))
{
    $tblRows1 .= "<tr>";
    $tblRows1 .= "<td>{$row['Skill_Name']}</td>";
    $tblRows1 .= "<td>{$row['Weight']}</td>";
    $tblRows1 .= "</tr>\n";
}

 

So I want to compare the weight and score and perform some simple maths on it, such as:

 

score - weight etc

 

would it be as simple as:

 

$some_variable=($row['Score'] - $row['Weight']) ??

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/149683-comparing-values-from-different-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.