By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

Simple question, but I`m puzzled :(

P: n/a
Hi!
I`ve got a simple question but I`m puzzled:( When I create variable: for example
$query for query to MySQL its obvieus that I want to use variables. Now should I do
something like that:
1) $query = "blahblahblah".$variable1."blahblahblah"
."blahblahblah".$variable2."blahblahblah";
OR
2) $query = "blahblahblah."$variable1."blahblahblah"
."blahblahblah."$variable2."blahblahblah";

It`s the 1st one right? I have to be sure:(
TIA

--
Best regards,
Maciej Nadolski
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sat, 4 Oct 2003 13:31:23 +0000 (UTC), Maciej Nadolski
<us****@WYTNIJ-TO.nadolski.net> wrote:
Hi!
I`ve got a simple question but I`m puzzled:( When I create variable: for example
$query for query to MySQL its obvieus that I want to use variables. Now should I do
something like that:
1) $query = "blahblahblah".$variable1."blahblahblah"
."blahblahblah".$variable2."blahblahblah";
OR
2) $query = "blahblahblah."$variable1."blahblahblah"
."blahblahblah."$variable2."blahblahblah";

It`s the 1st one right? I have to be sure:(


The first one is valid PHP, the second one is a syntax error, as PHP would
have told you if you'd tried it...

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote in
news:cm********************************@4ax.com:
The first one is valid PHP, the second one is a syntax error, as PHP
would
have told you if you'd tried it...

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


I haven`t run tests yet and I wanted to make sure before them so I asked. Thanks:)

--
Pozdrawiam,
Maciej Nadolski
Jul 17 '05 #3

P: n/a
On Sat, 04 Oct 2003 14:10:28 +0000, Maciej Nadolski wrote:
Andy Hassall <an**@andyh.co.uk> wrote in
news:cm********************************@4ax.com:
The first one is valid PHP, the second one is a syntax error, as PHP
would
have told you if you'd tried it...

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


I haven`t run tests yet and I wanted to make sure before them so I asked. Thanks:)


Well why the heck not?? A simple test would've answered your question more
quickly than posting to this newsgroup!
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #4

P: n/a
"Maciej Nadolski" <us****@WYTNIJ-TO.nadolski.net> wrote in message
news:Xn*******************************@193.110.122 .80...
Hi!
I`ve got a simple question but I`m puzzled:( When I create variable: for example $query for query to MySQL its obvieus that I want to use variables. Now should I do something like that:
1) $query = "blahblahblah".$variable1."blahblahblah"
."blahblahblah".$variable2."blahblahblah";
OR
2) $query = "blahblahblah."$variable1."blahblahblah"
."blahblahblah."$variable2."blahblahblah";

It`s the 1st one right? I have to be sure:(


What was the point of this question? I ask only because the only difference
between your examples would appear to be a typo (concatenation operator
inside quotes in second example).

- Virgil
Jul 17 '05 #5

P: n/a

"Maciej Nadolski" <us****@WYTNIJ-TO.nadolski.net> wrote in message
news:Xn*******************************@193.110.122 .80...
Hi!
I`ve got a simple question but I`m puzzled:( When I create variable: for example $query for query to MySQL its obvieus that I want to use variables. Now should I do something like that:
1) $query = "blahblahblah".$variable1."blahblahblah"
."blahblahblah".$variable2."blahblahblah";
OR
2) $query = "blahblahblah."$variable1."blahblahblah"
."blahblahblah."$variable2."blahblahblah";

It`s the 1st one right? I have to be sure:(
TIA

--
Best regards,
Maciej Nadolski


RTFM. If you did you would see that 1 is valid php and 2 is not, but that
neither are partiularly efficient.

You are using double quotes where single would suffice:

$query = 'blahblahblah'.$variable1.'blahblahblahblahblahbla h'
.$variable2.'blahblahblah';

would be favourable. If you really wanted to use doube quotes (maybe your
keyboard is broken?) then you could use:

$query = "blahblahblah{$variable1}blahblahblah
{$variable2}blahblahblah";

but this will be slower as php will be parsing the pre-defined text as well.

PS
--
Divide By Cucumber Error. Please Reinstall Universe And Reboot
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.