Re: Is this possible or am I on drugs :)
От | Ron Chmara |
---|---|
Тема | Re: Is this possible or am I on drugs :) |
Дата | |
Msg-id | 3A242EDD.3C5645F3@opus1.com обсуждение исходный текст |
Ответ на | Re: Is this possible or am I on drugs :) (shawn everett <everett@pgweb.com>) |
Ответы |
Solved: Is this possible or am I on drugs :)
|
Список | 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.
В списке pgsql-general по дате отправления: