Re: Optional fields - Mailing list pgsql-php

From Dan Wilson
Subject Re: Optional fields
Date
Msg-id 013301c08056$49e96830$078353d8@danwilson
Whole thread Raw
In response to Optional fields  (Timothy_Maguire@hartehanks.com)
List 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@hartehanks.com>
To: <pgsql-php@postgresql.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.
>
>


pgsql-php by date:

Previous
From: Timothy_Maguire@hartehanks.com
Date:
Subject: Optional fields
Next
From: Stefan Gastaldon
Date:
Subject: PSQL only one query per page