Re: Optional fields - Mailing list pgsql-php

From Timothy_Maguire@hartehanks.com
Subject Re: Optional fields
Date
Msg-id 852569D7.004FE2B2.00@linmail.hartehanks.com
Whole thread Raw
In response to Optional fields  (Timothy_Maguire@hartehanks.com)
List pgsql-php
Thank you.  I used a little different code but it still worked.  Here is a
snippet of it:

$query = "select employee_id, job_title, department from employee where
current_status = 'A' ";
if ($first != "")
     {
     $query .= "and first_name ~* '$first' ";
     }

... all my other fields....

$query .= "order by last_name;";

Becasue I had an order by, I didn't have to use the ereg_replace at the bottom.

Thank you to Dan and to Josh for pushing me in the right direction.

Tim.




"Dan Wilson" <phpPgAdmin@acucore.com> on 01/17/2001 02:22:44 AM

To:   Timothy Maguire/Data-Technologies/Harte-Hanks@Harte-Hanks,
      pgsql-php@postgresql.org
cc:

Subject:  Re: [PHP] Optional fields



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: "Dan Wilson"
Date:
Subject: Re: PSQL only one query per page
Next
From: "Julio Cuz, Jr."
Date:
Subject: Order