From: Chris Ryan <chris@greatbridge.com>
To: Christian Marschalek <cm@chello.at>
Cc: [PHP] PostgreSQL <pgsql-php@postgresql.org>
Subject: Re: Variable question...
Date: Fri, 11 May 2001 08:02:06 -0400
Message-ID: <3AFBD4BE.D62E2840@greatbridge.com> (raw)
References: <000501c0d8e8$f6ab2f00$0200a8c0@server>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: chris@greatbridge.com, cm@chello.at
Subject: Re: Variable question...
In-Reply-To: <3AFBD4BE.D62E2840@greatbridge.com>
References: <000501c0d8e8$f6ab2f00$0200a8c0@server> <3AFBD4BE.D62E2840@greatbridge.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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