Page 1 of 1

Wierd print() problem

Posted: Tue Apr 20, 2004 12:04 pm
by Bill H
Consider the following code:

Code: Select all

<?php
          while($Xrow = mysql_fetch_array($Xres))      // list the transactions (usually only one, but...)
          {
               print("<a href="javascript:firstWindow('revtran.php?Seq=" . $row['Seq']);
*             print("&Tid=" . $Xrow['id'] . "',210,410)"><img src='images/bdot.gif' border=0></a>");
               print("&nbsp;<span class='green-10'>");
               print($Xrow['Tran'] . ", $" . $Xrow['Tamt'] . "</span>");
               if (strlen($Xrow['Doc1'])) print("<br>Use " . $Xrow['Doc1']);
               if (strlen($Xrow['Doc1']) && $Xrow['Amt1'] > 0.00) print(", $" . $Xrow['Amt1']);
               if (strlen($Xrow['Doc2'])) print("<br>and " . $Xrow['Doc1']);
               if (strlen($Xrow['Doc2']) && $Xrow['Amt2'] > 0.00) print(", $" . $Xrow['Amt1']);
               print("<br>");
          }
          print("<a href="javascript:firstWindow('revtran.php?Seq=" . $row['Seq']);
*        print("&Tid=" . $Xrow['id'] + 1 . "',210,410)"><img src='images/bdot.gif' border=0></a>");
          print("&nbsp;Add new transaction<br>");
?>
Now I know some will say I should use echo instaed, etc, but aside from that --- My concern is the two lines marked with stars, which print differently.

The first one, within the while loop, prints the way I want to

Code: Select all

revtran.php?Seq=1&amp;Tid=1
The second one does not,, and I cannot see the difference between them!

Code: Select all

revtran.php?Seq=11
It's not printing the "&Tid=" at all. Can someone tell me what the sam hill I am missing?
:?

Posted: Tue Apr 20, 2004 12:08 pm
by magicrobotmonkey
I'm not sure about this math in the middle of a string:
$Xrow['id'] + 1
try doing it before hand

Posted: Tue Apr 20, 2004 12:40 pm
by Bill H
That part is working fine, it's the "&Tid=" not being printed that is the problem.

Where $Xres is returning no results it prints "revtran.php?Seq=11" and where there is one result in the return it prints "revtran.php?Seq=12" just as would be expected, given that it isn't printing the "&Tid=" string.

The question is, why is it printing that string one place and not the other?
:?:

Posted: Tue Apr 20, 2004 12:43 pm
by magicrobotmonkey
Is it not printing that entire line?

Posted: Tue Apr 20, 2004 12:47 pm
by Bill H
It prints everything except "&Tid="

Posted: Tue Apr 20, 2004 3:34 pm
by feyd
. operator has precedence over + operator.. surround the equation is parathesis.

Posted: Tue Apr 20, 2004 6:27 pm
by Bill H
Duh. Thanks.

I use parentheses in mathmetical and semi-mathmetical expressions so heavily that I seldom even consider operator precedence -- that is to say I tend make it a non-issue by the use of parens for readability purposes.

The downside of that is I think about it too little.
:oops: