pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Variable question...
6+ messages / 4 participants
[nested] [flat]

* Variable question...
@ 2001-05-10 00:34  Christian Marschalek <cm@chello.at>
  0 siblings, 3 replies; 6+ messages in thread

From: Christian Marschalek @ 2001-05-10 00:34 UTC (permalink / raw)
  To: pgsql-php

Can anyone please tell me why this does not work:

$result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =
$HTTP_SESSION_VARS['user_tabelleXu_o_plz']");

And I have to do the following instead?

$plz = $HTTP_SESSION_VARS['user_tabelleXu_o_plz'];
$result = query_trans($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz =
$plz");

Tia again Chris




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Variable question...
@ 2001-05-10 00:40  Mitch Vincent <mitch@venux.net>
  parent: Christian Marschalek <cm@chello.at>
  2 siblings, 1 reply; 6+ messages in thread

From: Mitch Vincent @ 2001-05-10 00:40 UTC (permalink / raw)
  To: Christian Marschalek <cm@chello.at>; pgsql-php

Try --

    $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =".
    $HTTP_SESSION_VARS["user_tabelleXu_o_plz"]);

> And I have to do the following instead?
> 
> $plz = $HTTP_SESSION_VARS['user_tabelleXu_o_plz'];
> $result = query_trans($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz =
> $plz");
> 
> Tia again Chris
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Variable question...
@ 2001-05-10 00:48  Chris Smith <csmith@squiz.net>
  parent: Christian Marschalek <cm@chello.at>
  2 siblings, 1 reply; 6+ messages in thread

From: Chris Smith @ 2001-05-10 00:48 UTC (permalink / raw)
  To: Christian Marschalek <cm@chello.at>; pgsql-php

Hey,

It might not be translating the array contents properly (because of the 
quotes inside the $HTTP_SESSION_VARS? Not sure)...

Try -

$result = pg_exec($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz = 
".$HTTP_SESSION_VARS['user_tabelleXu_o_plz']);

which basically appends the session variable onto the end of the query..

> Can anyone please tell me why this does not work:
>
> $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =
> $HTTP_SESSION_VARS['user_tabelleXu_o_plz']");
>
> And I have to do the following instead?
>
> $plz = $HTTP_SESSION_VARS['user_tabelleXu_o_plz'];
> $result = query_trans($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz =
> $plz");

-- 

     Chris Smith
http://www.squiz.net



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* RE: Variable question...
@ 2001-05-10 00:55  Christian Marschalek <cm@chello.at>
  parent: Mitch Vincent <mitch@venux.net>
  0 siblings, 0 replies; 6+ messages in thread

From: Christian Marschalek @ 2001-05-10 00:55 UTC (permalink / raw)
  To: 'Mitch Vincent' <mitch@venux.net>; +Cc: pgsql-php

> Try --
> 
>     $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle 
> WHERE o_plz =".
>     $HTTP_SESSION_VARS["user_tabelleXu_o_plz"]);

Hell..... I'm doing this anyway in another script.. Thanks ;)

But I wonder how you would do that within the string correctly :) (the
error message php gives me does not tell me anything usefull;)




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* RE: Variable question...
@ 2001-05-10 01:04  Christian Marschalek <cm@chello.at>
  parent: Chris Smith <csmith@squiz.net>
  0 siblings, 0 replies; 6+ messages in thread

From: Christian Marschalek @ 2001-05-10 01:04 UTC (permalink / raw)
  To: 'Chris Smith' <csmith@squiz.net>; +Cc: pgsql-php

Thanks :) Got that answer just a moment ago... 
I'm doing this in another script anyway... *dizzy*

Well now it would be interessting to know how to accomplish this without
this "work around".
The PHP authors must have thought about a way to use variables with text
marks inside strings, don't they?

regards

> -----Original Message-----
> From: Chris Smith [mailto:csmith@squiz.net] 
> Sent: Thursday, May 10, 2001 2:49 AM
> To: Christian Marschalek; [PHP] PostgreSQL
> Subject: Re: [PHP] Variable question...
> 
> 
> Hey,
> 
> It might not be translating the array contents properly 
> (because of the 
> quotes inside the $HTTP_SESSION_VARS? Not sure)...
> 
> Try -
> 
> $result = pg_exec($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz = 
> ".$HTTP_SESSION_VARS['user_tabelleXu_o_plz']);
> 
> which basically appends the session variable onto the end of 
> the query..
> 
> > Can anyone please tell me why this does not work:
> >
> > $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =
> > $HTTP_SESSION_VARS['user_tabelleXu_o_plz']");
> >
> > And I have to do the following instead?
> >
> > $plz = $HTTP_SESSION_VARS['user_tabelleXu_o_plz'];
> > $result = query_trans($c1, "SELECT o_plz FROM ort_tabelle 
> WHERE o_plz 
> > =
> > $plz");
> 
> -- 
> 
>      Chris Smith
> http://www.squiz.net
> 




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Variable question...
@ 2001-05-11 12:02  Chris Ryan <chris@greatbridge.com>
  parent: Christian Marschalek <cm@chello.at>
  2 siblings, 0 replies; 6+ messages in thread

From: Chris Ryan @ 2001-05-11 12:02 UTC (permalink / raw)
  To: Christian Marschalek <cm@chello.at>; +Cc: pgsql-php

Christian,

	There are one of three ways this can be done:

	1. as you mentioned below; is to assign the variable to another
variable first.
	2. use the . syntax for string, as was mentioned in other responses to
your question
	3. use {} syntax to explicitly tell PHP what is your variable. see
below for example

	The thing with PHP is that when parsing strings it needs to determine
what is string and what is variable references. When you are using
arrays and other complex access methods for object, classes and the like
PHP gets confused and doesn't understand what to do. To solve this
problem you can do one of the three listed above. The first is basically
taking the complex access method and assigning to a variable that has
the simple access method. The third uses PHP syntax to explicitly tell
PHP what your variable is. Using you example you would write it like
this:

    $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =
${HTTP_SESSION_VARS['user_tabelleXu_o_plz']}");

NOTE: the {} brackets after the $ encapsulating the entire variable
access.

	My preference is to use method 2 as it tends to be cleaner and a little
easier to read but it is nice to know all the options as it depends on
you application as to which is best for you.

Chris Ryan
chris@greatbridge.com

Christian Marschalek wrote:
> 
> Can anyone please tell me why this does not work:
> 
> $result = pg_exec($c1,"SELECT o_plz FROM ort_tabelle WHERE o_plz =
> $HTTP_SESSION_VARS['user_tabelleXu_o_plz']");
> 
> And I have to do the following instead?
> 
> $plz = $HTTP_SESSION_VARS['user_tabelleXu_o_plz'];
> $result = query_trans($c1, "SELECT o_plz FROM ort_tabelle WHERE o_plz =
> $plz");
> 
> Tia again Chris
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2001-05-11 12:02 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-10 00:34 Variable question... Christian Marschalek <cm@chello.at>
2001-05-10 00:40 ` Mitch Vincent <mitch@venux.net>
2001-05-10 00:55   ` Christian Marschalek <cm@chello.at>
2001-05-10 00:48 ` Chris Smith <csmith@squiz.net>
2001-05-10 01:04   ` Christian Marschalek <cm@chello.at>
2001-05-11 12:02 ` Chris Ryan <chris@greatbridge.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox