Log in

View Full Version : Subtraction operator not working!!



dcr33
05-27-2012, 09:57 AM
Hi
I am trying to subtract a id from a roll number from a database. But the subtraction is not occurring !!
This is my code :
echo"
<TR>
<TD>$c</TD>
<TD>$row[name]</TD>
<TD>$row[roll]-$row[id]</TD>
<TD><A HREF='1.php?page=$_GET[page]&upd=$row[id]'>UPDATE<A></TD>
</TR>";
I am trying various ways like -
"$row[roll]"-"$row[id]"
OR
like this :

"$row[roll]\"-\"$row[id]\"
etc etc. but none is working.
Please can anyone tell me how to do the subtraction between row[roll] and row[id]??

djr33
05-27-2012, 10:00 AM
Don't put it in quotes. It's a good idea to not put quotes around your variables anyway. Plus, it shouldn't work in quotes when you're using array keys in the []s.


echo"
<TR>
<TD>".$c."</TD>
<TD>".$row[name]."</TD>
<TD>".($row[roll]-$row[id])."</TD>
<TD><A HREF='1.php?page=".$_GET[page]."&upd=".$row[id]."'>UPDATE<A></TD>
</TR>"; I also put the subtraction operation in parentheses to avoid any potential ambiguities. (I think PHP first joins with . then subtracts with -, which would give you the wrong result obviously.)