Page 1 of 1
Simple Maths functions
Posted: Mon Mar 16, 2009 1:02 pm
by nishmgopal
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:
Code: Select all
$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
Re: Simple Maths functions
Posted: Mon Mar 16, 2009 1:16 pm
by prgmctan
nishmgopal wrote: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:
Code: Select all
$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
I think you're going to need to create new variables for the second query or it will become overwritten, but I could be wrong.
Re: Simple Maths functions
Posted: Mon Mar 16, 2009 1:57 pm
by nishmgopal
I tried that, and 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 ='Manager'";
$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 ='Nish'";
$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=($row['Score'] - $row1['Weight']);
echo "$diff";
?>
And the return I get is 0.
Do I need to loop? and if so how? Thanks
Re: Simple Maths functions
Posted: Mon Mar 16, 2009 3:35 pm
by nishmgopal
can some please help...I have tried numerous things wth no luck...
Re: Simple Maths functions
Posted: Mon Mar 16, 2009 3:35 pm
by John Cartwright
Please do not bump your post within 24 hours of the last.
Re: Simple Maths functions
Posted: Wed Mar 18, 2009 10:44 pm
by prgmctan
nishmgopal wrote:I tried that, and 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 ='Manager'";
$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 ='Nish'";
$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=($row['Score'] - $row1['Weight']);
echo "$diff";
?>
And the return I get is 0.
Do I need to loop? and if so how? Thanks
Are the scores and weights related to the people? If so, you should combine your tables and make your life a lot easier.
Re: Simple Maths functions
Posted: Thu Mar 19, 2009 12:11 am
by php_east
i don't understand this. why are you posting the same problem again under a different name ?
you said in the previous thread that you will investigate or try and report back your findings, and so we left it at that,
viewtopic.php?f=1&t=97198
now you appear here under a different title with the exact same problem.
there is a difference between asking for help and leading us to work for you. i felt i wasted my time trying to help you previously. at least if you wanted someone else to come in and help, you could have done so in the already existing thread. or is it that the ideas/solutions given were not at all useable ? and the time spent studying your problem entirely wasted ?
Re: Simple Maths functions
Posted: Fri Mar 20, 2009 5:16 am
by nishmgopal
I havent re-posted this...i posted the loop question before this, and I havent had the chance to try the suggestion you and other made, but will be doing it today, and will be reporting back.
Not asking anyone to leade my work, but I am asking for advice...isnt that what this forum is for?
I appreciate the help given, and will be seeing if I can use the advise and will report back later today.
Thank you