Re: Postgres access using PHP3

From: Andy Holman <info(at)i-developit(dot)com>
To: John Poltorak <jp(at)eyup(dot)org>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Postgres access using PHP3
Date: 2001-01-19 22:15:05
Message-ID: 3A68BC69.5BAFDA5D@i-developit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

John,
What you will need to do is create a table that has the
town names in it.
Example:

CREATE TABLE towns
(
town_id serial,
townName text,
PRIMARY KEY(town_id, townName)
);

SO... your query would look something like

SELECT townName FROM towns;

I never used the pgsql functions in php so you will
have to look those up on php.net, I normally use
phpLib which allows me to write for many different DB
types.

But I think it would look something like:

$query = "SELECT townName FROM towns";
$result = pg_exec($connectid, $query);

echo "<SELECT NAME=\"towns\">";
while($row = pg_fetch_array($result))
{
echo "<option
value=\"".$row["townName"]."\">".$row["townName"]."</option>";
}
echo "</SELECT>";

The above, (keep in mind my pgsql functions may be off), but that should
print out your list of townNames in a option list.

Hope this helps.

--Andy

John Poltorak wrote:
>
> On Fri, Jan 19, 2001 at 04:13:21PM -0500, Andy Holman wrote:
> > John,
> > Not sure exactly what you mean. Do you know the
> > column names to the table in the db or is that
> > what you are trying to get? Or do you mean you
> > are just trying to print out the results of a
> > query into a drop down list?
> >
> > Let me know and I will give you some code.
>
> Hi Andy,
>
> I'm going to attach some sample PHP code which hopefully illustrates
> what I mean...
>
> The the first selection offers a list of monthnames. What I want to
> do instead is provide a list of values from a table ie such as towns.
> The selected town will then be used for the WHERE clause in a subsequent
> SELECT.
>
> I hope you understand what I'm getting at.
>
> > --Andy
> >
> >
> >
> > John Poltorak wrote:
> > >
> > > I'm trying out PHP3 for accesing Postgres through a Web interface
> > > and am having a problem coming up with the correct code...
> > >
> > > I'd like to retreive a list of values for a key field and then
> > > provide this to the user in the form of a drop down selection list,
> > > but I can't work out how to get the values into an array.
> > >
> > > I must be missing something as I can't a way of doing it...
> > >
> > > Any sample code snippets would be much appreciated.
> > >
> > > --
> > > John
>
> --
> John
>
> ------------------------------------------------------------------------
>
> M:\repository\$$$.CDs\CORE_PHP\EXAMPLES\18-11.php3Name: M:\repository\$$$.CDs\CORE_PHP\EXAMPLES\18-11.php3
> Type: Plain Text (text/plain)

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Stefan Waidele jun. 2001-01-19 22:16:56 Re: Re: Interval output format
Previous Message Albert REINER 2001-01-19 22:09:31 Index on function referring other table