Wierd print() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Wierd print() problem

Post 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?
:?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

I'm not sure about this math in the middle of a string:
$Xrow['id'] + 1
try doing it before hand
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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?
:?:
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Is it not printing that entire line?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

It prints everything except "&Tid="
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

. operator has precedence over + operator.. surround the equation is parathesis.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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:
Post Reply