nishmgopal Posted March 16, 2009 Share Posted March 16, 2009 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 More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 would it be as simple as: $some_variable=($row['Score'] - $row['Weight']) ?? Why not, have you tried it? Link to comment https://forums.phpfreaks.com/topic/149683-comparing-values-from-different-tables/#findComment-786016 Share on other sites More sharing options...
nishmgopal Posted March 16, 2009 Author Share Posted March 16, 2009 I didnt think I posted this question with the right title, I have posted it again under "simple maths function". I did try that code and it returned 0. Link to comment https://forums.phpfreaks.com/topic/149683-comparing-values-from-different-tables/#findComment-786020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.