Re: Is this possible or am I on drugs :)

From: Ron Chmara <ron(at)opus1(dot)com>
To: shawn everett <everett(at)pgweb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is this possible or am I on drugs :)
Date: 2000-11-28 22:17:01
Message-ID: 3A242EDD.3C5645F3@opus1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

shawn everett wrote:
> > What do you consider "passing a parameter to the view" to be?
> This is where Microsoft Access has twisted me :)
> Access as you may or may not know allows you to use parameters in a query:
> SELECT * FROM table WHERE table.pkey=[Enter The Primary Key];
> The bit in [] represents a prompt to the user. They can also be filled in
> programatically.

In PHP, that's just a variable passed from a prior page....

> The basic select statement for my problem is going to work as follows:
> select colA, colB, colA+colB*0.4 as f1, colC, colC+colD*9 as f2 from table
> where date=SomeDateEnteredByTheUser;
> Can I pass SomeDateEnteredByTheUser to Postgres in some way and get back
> the set of records I want? If I can is there a way to call this from PHP?

You _are_ asking pretty much a basic PHP question.

$result = pg_exec($conn,"select colA, colB, colA+colB*0.4 as f1, colC, colC+colD*9
as f2 from table where date=$SomeDateEnteredByTheUser;");

Where you are passing "$SomeDateEnteredByTheUser" from a prior page as
a form item.

Want to get really wacky? Make them all variables, passed from the prior
page....($colA, $colB, $colC, $colD, $f1, $f2, $table, etc..)

$built_statement = "select $colA, $colB, $colA"."+".$colB"."*"."0.4 "
$built_statement =. "as $f1, $colC, $colC"."+"."$colD"."*"."9 as $f2"
$built_statement =. " from $table where date= $SomeDateEnteredByTheUser";

$result = pg_exec($conn, $built_statement);

> If I can't and end up dynamically writing the query and sumbitting that
> to Postgres is this a smart way to do it?
> Or should I simply query out the basic values: colA, colB, colC and colD
> and then do the calculations within PHP?

Either way works. <shrug>. I do lot's of my calcs in PHP, because I can
quickly edit them at the same time as my display code. Other things are
far too complex or repetitive to bother PHP with, so I do 'em in Pg. In
general, though, you'll find your code more flexible if it's variable
driven....

-Bop

--
Brought to you from boop!, the dual boot Linux/Win95 Compaq Presario 1625
laptop, currently running RedHat 6.1. Your bopping may vary.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message GH 2000-11-28 22:41:20 Re: How to view the code in a function??
Previous Message Tom Lane 2000-11-28 21:54:35 Re: Create View failing