Simple question, but I`m puzzled :(

This is a discussion on Simple question, but I`m puzzled :( within the PHP Language forums, part of the PHP Programming Forums category; Hi! I`ve got a simple question but I`m puzzled:( When I create variable: for example $query for query ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-04-2003
Maciej Nadolski
 
Posts: n/a
Default Simple question, but I`m puzzled :(

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
Reply With Quote
  #2 (permalink)  
Old 10-04-2003
Andy Hassall
 
Posts: n/a
Default Re: Simple question, but I`m puzzled :(

On Sat, 4 Oct 2003 13:31:23 +0000 (UTC), Maciej Nadolski
<usenet@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 (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Reply With Quote
  #3 (permalink)  
Old 10-04-2003
Maciej Nadolski
 
Posts: n/a
Default Re: Simple question, but I`m puzzled :(

Andy Hassall <andy@andyh.co.uk> wrote in
news:cmjtnvc5efjhqrcknd0gcemirgehu7r4i4@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 (andy@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
Reply With Quote
  #4 (permalink)  
Old 10-04-2003
Jeffrey Silverman
 
Posts: n/a
Default Re: Simple question, but I`m puzzled :(

On Sat, 04 Oct 2003 14:10:28 +0000, Maciej Nadolski wrote:

> Andy Hassall <andy@andyh.co.uk> wrote in
> news:cmjtnvc5efjhqrcknd0gcemirgehu7r4i4@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 (andy@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/

Reply With Quote
  #5 (permalink)  
Old 10-05-2003
Virgil Green
 
Posts: n/a
Default Re: Simple question, but I`m puzzled :(

"Maciej Nadolski" <usenet@WYTNIJ-TO.nadolski.net> wrote in message
news:Xns940A9DE54605Dusenetnadolskinet@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


Reply With Quote
  #6 (permalink)  
Old 10-05-2003
Psychic StickleBrick
 
Posts: n/a
Default Re: Simple question, but I`m puzzled :(


"Maciej Nadolski" <usenet@WYTNIJ-TO.nadolski.net> wrote in message
news:Xns940A9DE54605Dusenetnadolskinet@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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0