473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"<td><input name='".$i-2."'

aa
I am traing to output the following HTML string from PHP:
"<td><input name='".$i-2."' size='2' type='text'
onBlur='myfunction(".$i-2.")'></td>"
But it somehow mistreats $i-2. PHP does not throw any errors but the
browser renders the table incorrectly.
I got round this by introducing another variable
j=i-2 and using it in place of i-2
It works. However I am interested to understand why is does not work with
i-1. Any comments?
Jul 17 '05 #1
3 2404
.oO(aa)
I am traing to output the following HTML string from PHP:
"<td><input name='".$i-2."' size='2' type='text'
onBlur='myfunction(".$i-2.")'></td>"
But it somehow mistreats $i-2. PHP does not throw any errors but the
browser renders the table incorrectly.
I get a parse error, but even without that the above would not do what
you want. In fact what you are trying do to is to print a difference of
these three strings:

"<td><input name='".$i
2."' size='2' type='text' onBlur='myfunction(".$i
2.")'></td>"
I got round this by introducing another variable
j=i-2 and using it in place of i-2
It works.


There are some other ways to solve that issue:

1) Use parentheses around the $i-2, e.g.

print "<td><input name='".($i-2)."' size='2' ...";

2) Use printf() and a format string with placeholders, which are then
replaced with $i-2. See the manual on sprintf() for details.

Micha
Jul 17 '05 #2
aa
Thanks, Micha
It never occured to me that concatination could have hight priority than
arithmetic operations.

Jul 17 '05 #3
aa wrote:
I am traing to output the following HTML string from PHP:
"<td><input name='".$i-2."' size='2' type='text'
onBlur='myfunction(".$i-2.")'></td>"
But it somehow mistreats $i-2. PHP does not throw any errors but the
browser renders the table incorrectly.
I got round this by introducing another variable
j=i-2 and using it in place of i-2
It works. However I am interested to understand why is does not work with
i-1. Any comments?


Hi,

I noticed that problem too.
I guess there is a very valid reason why it happens. :-)

Solve it by using ()
so:
$i=1;
echo "testing i+1=".$i+1; // gives 1

but

echo "testing i+1=".($i+1); // gives 2
Possible reason (as a guru to be sure. :P)
I expect PHP interprets the line as:
$result = (print "i+1=".$i) + 1;
// result contains 2 now!

where:

$result = (print "i+1=".($i + 1);
// result contains 1 now!
Regards,
Erwin Moller
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: google12 | last post by:
hi, May anyone help me? I need a lib which support .jpeg file with RGBA mode. PIL seems to support RGB and CMYK mode only... Thanks for your help.
15
by: Marc Le Roy | last post by:
Hello, ADA Ravenscar is a restricted subset of the ADA language that has been defined for real-time software development in safety critical applications. Completed with additional restrictions...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
17
by: Victor Bazarov | last post by:
Interesting article. However, it starts with an example which I find rather misleading. I hope the author (Christopher Diggins) wouldn't mind if I post a quote from the article. I know he...
2
by: Martin Magnusson | last post by:
It seems that the following code is not valid, but I need to find a workaround. Both gcc and Comeau tells me that j can't be used as a template argument, even though it's declared as a const...
2
by: Michael Olea | last post by:
Hiya. Frequently (as in at least twice now) I find that when I write some sort of container I want at least two out of three possible versions: o fixed max size known at compile time o fixed...
0
by: tmartsum | last post by:
I have a discussion in comp.std.c++ After a (bit stupid) suggestion on representing a fixed 'big' length int I moderated it to "Bitfields-ints should be allowed to have any fixed length" I...
7
by: gretean | last post by:
I have a problem that's driving me crazy involving Microsoft's ability to deduce template parameters. I am using Visual Studio .NET (aka VC7?), and it gives an error compiling the following code....
4
by: Julek | last post by:
Hi, I wanted to know, if there is guarantee that a specific variable is always the same number of bytes forward than the beginning of the struct/class. Example: class MyClass { .... int var;...
6
by: Peter | last post by:
Hi I have a number of arrays of longs, from which I need to find a single array which only contains the values which appear in all the original arrays. For example, I could have the three...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.