473,320 Members | 1,722 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.

can anyone tell me what is wrong in this

190 100+
[PHP]echo "<tr><td>Bank Code </td><td><input type='text' name='bcode[$i]' value='".$bcode."' onblur='modify_rec(<?=$bcode?>,<?=$brcode?>,this.v alue,<?=$bc?>);></td>";[/PHP]
Jun 3 '08 #1
11 1470
hsriat
1,654 Expert 1GB
[PHP]echo "<tr><td>Bank Code </td><td><input type='text' name='bcode[$i]' value='".$bcode."' onblur='modify_rec(<?=$bcode?>,<?=$brcode?>,this.v alue,<?=$bc?>);></td>";[/PHP]
I guess you actually wanted to write this...
[php]echo "<tr><td>Bank Code </td><td><input type=\"text\" name=\"bcode".$i."\" value=\"".$bcode."\" onblur=\"modify_rec('".$bcode."','".$brcode."',thi s.value,'".$bc."') /></td>";[/php]
Jun 3 '08 #2
Atli
5,058 Expert 4TB
I guess you actually wanted to write this...
[php]echo "<tr><td>Bank Code </td><td><input type=\"text\" name=\"bcode".$i."\" value=\"".$bcode."\" onblur=\"modify_rec('".$bcode."','".$brcode."',thi s.value,'".$bc."') /></td>";[/php]
Why would you quote your string with a double quote, only to have to escape all the other double-quotes, and them exit the string to add the variables?

Try
[php]echo "<tr><td>Bank Code </td><td><input type=\"text\" name=\"bcode{$i}\" value=\" {$bcode}\" onblur=\"modify_rec('{$bcode}', '{$brcode}', this.value,'{$bc}')\" /></td>";[/php]
Or even
[php]echo <<<EndString
<tr><td>Bank Code </td><td><input type="text" name="bcode{$i}" value="{$bcode}" onblur="modify_rec('{$bcode}', '{$brcode}', this.value,'{$bc}')" /></td>
EndString;
[/php]
Jun 3 '08 #3
hsriat
1,654 Expert 1GB
Hey Atli, I could not understand why would you recommend {$x} over ".$x.".

With the later thing (one with dot and double quote), I became familiar with when I learned some basics of Linux. Since then I've been using that. I never used curly braces. Any difference?
Jun 3 '08 #4
Atli
5,058 Expert 4TB
The main reason I use them like that is because it looks better. Using the method you used you got all these extra quote-marks and back-slashes getting in the way. The curly braces aren't used for anything else in the string, so they stand out.

I did a little performance test on my test server, just to see if there were any added performance benefits, but these two methods appear to perform pretty much at the same speed.
Although for large strings with many added variables, the ".$var." method lags behind.

Another interesting thing. Just putting the $var inside the string, without the curly braces, is faster than any of the alternatives. A test that took both the ".$var." and the {$var} methods around 1.2 seconds, the "$var" method only took around 1.1 second.
That's like 9% faster :)
Jun 3 '08 #5
hsriat
1,654 Expert 1GB
Another interesting thing. Just putting the $var inside the string, without the curly braces, is faster than any of the alternatives.
LOL... so we both are useless.. ?



But I don't know, I am reluctant to use $var without anything. I think I somewhere within believe that its not the right way.

Jun 3 '08 #6
Markus
6,050 Expert 4TB
The OP string is awful!

It jumps from parsing vars in a string, to then using the phpshorttags to echo them!

Jeez, louise!

I, when using arrays, use "string string {$array[1]}" I don't do it for just plain variables, though.

Something else I tend to do is:
[php]
echo ' use single quotes, then when a var comes along ' . $var . ' and continue the string ';
[/php]
I find this to be more attractive, also.
Jun 3 '08 #7
hsriat
1,654 Expert 1GB
I do the same thing, not here, but in JavaScript.
Expand|Select|Wrap|Line Numbers
  1. x.innerHTML = '<a id="'+id+'" href="markus.php" title="Markus is a good boy">Don\'t click.</a>' ;
Jun 3 '08 #8
Atli
5,058 Expert 4TB
Using single quotes and '. $var .', like you did there Markus, is probably the best way to go when you don't have a lot of variables to add into a string.
PHP doesn't look for variable names in single-quoted strings so it will probably give you a little performance boost.

Although, if I may nitpick a little :)
When you are using the echo command, you are probably better of using commas than periods.
Like:
Expand|Select|Wrap|Line Numbers
  1. # Instead of 
  2. echo "Some text". $variable ."more text". $anothervar;
  3. # Do
  4. echo "Some text", $variable, "more text", $anothervar;
  5.  
What that does; instead of creating a new string out of all the parts and then printing it, it just prints each part individually. Which should give a slight speed boost. (Very slight :P)
Jun 3 '08 #9
Markus
6,050 Expert 4TB
Using single quotes and '. $var .', like you did there Markus, is probably the best way to go when you don't have a lot of variables to add into a string.
PHP doesn't look for variable names in single-quoted strings so it will probably give you a little performance boost.

Although, if I may nitpick a little :)
When you are using the echo command, you are probably better of using commas than periods.
Like:
Expand|Select|Wrap|Line Numbers
  1. # Instead of 
  2. echo "Some text". $variable ."more text". $anothervar;
  3. # Do
  4. echo "Some text", $variable, "more text", $anothervar;
  5.  
What that does; instead of creating a new string out of all the parts and then printing it, it just prints each part individually. Which should give a slight speed boost. (Very slight :P)
Preference, preference.
Performance, at the minute, isn't of great concern to me.

Plus, as you may have noticed, I am a comma-junkie! I'd get confused, I think, with, all, the, extra, commas.

;]
Jun 3 '08 #10
Atli
5,058 Expert 4TB
Preference, preference.
Performance, at the minute, isn't of great concern to me.

Plus, as you may have noticed, I am a comma-junkie! I'd get confused, I think, with, all, the, extra, commas.

;]
I know the feeling
The comma to the rescue! 8-]
Jun 3 '08 #11
pbmods
5,821 Expert 4TB
Getting back on topic (*ahem*)....

As Markus pointed out, there's PHP short tag syntax in there, which is not what you need. That will get output as straight-up text instead of getting executed.

Try using hsriat's or Atli's solution, instead.

[EDIT: Oh, was that a link to my blog back there? Never mind; carry on O:) ]
Jun 4 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is...
102
by: RFox | last post by:
I date back to the early days of the web when HTML was limited but very managable, and have always maintained that hand-coding HTML gives you far better control and cleaner HTML markup than any...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
11
by: Aing | last post by:
Anyone knows what can be cause of this problem? //////////////////////////////////////////////////////////// typedef struct _date_struct { int date,month,year; }date_struct; Class Date {...
7
by: Skc | last post by:
Hullo Just like to check whether anyone has tried RentACoder. I intend to farm out a small job that must use C#, WinForms, ADO.Net for around US$400, but don't know whether RentACoder is...
2
by: Tony | last post by:
I found similar code for encoding/decoding strings in VB which works fine. However I wanted to use it in a C# projected and can't get it to work. When it executes the TransformFinalBlock() call at...
8
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information...
29
by: Roy Gourgi | last post by:
Hi, I am new to C#. I have the same time scheduling program written in C++ and it is 5 times faster than my version in C#. Why is it so slow as I thought that C# was only a little slower than...
33
by: O-('' Q) | last post by:
....to translate the following to C#.NET style? var i: Integer; begin txtMyIP.Lines.Clear; sHTML := HTTP.Get('http://www.network-tools.com/'); if sHTML = '' then Exit; sIpAddr := 'IP...
32
by: Kevin Walzer | last post by:
I'm a Tcl/Tk developer who has been working, slowly, at learning Python, in part because Python has better support for certain kinds of applications that I want to develop than Tcl/Tk does....
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.