Results 1 to 2 of 2

Thread: Subtraction operator not working!!

  1. #1
    Join Date
    Jul 2011
    Posts
    58
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Subtraction operator not working!!

    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 :
    PHP 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 -
    PHP Code:
    "$row[roll]"-"$row[id]
    OR
    like this :
    PHP Code:
    "$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]??

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.

    PHP 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 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.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    dcr33 (05-30-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •