Re: Optional fields

From: "Dan Wilson" <phpPgAdmin(at)acucore(dot)com>
To: <Timothy_Maguire(at)hartehanks(dot)com>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Optional fields
Date: 2001-01-17 07:22:44
Message-ID: 013301c08056$49e96830$078353d8@danwilson
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

You can do this by just using PHP to build your SQL statment.

if (!empty($first_name)) {
$sql_query .= " first_name = '$first_name' AND";
}

Do that for each of the fields you want to be able to search on. If they
put something in, then it will be included in the SQL SELECT. Remember, you
have to strip off the last AND. You can do this with a simple:

$sql_query = ereg_replace(" AND$", "", $sql_query);

-Dan

----- Original Message -----
From: <Timothy_Maguire(at)hartehanks(dot)com>
To: <pgsql-php(at)postgresql(dot)org>
Sent: Tuesday, January 16, 2001 6:57 AM
Subject: [PHP] Optional fields

> I have form that is used for searching a table of phone numbers. I want
the
> user to be able to search by first name, last name, manager, extension,
> building, title, and department, These are all fields in the employee
table.
> But i don't want to have any requred fields. I was wonder what would be
the
> best way to query the table by ony filling in a few of the fields in the
form.
> I want to use "and" in my sql statement. Does anyone have any suggestions
on
> where I can start?
>
> Thanks,
> Tim.
>
>

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Dan Wilson 2001-01-17 08:13:34 Re: PSQL only one query per page
Previous Message Stefan Gastaldon 2001-01-17 07:04:41 PSQL only one query per page