pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Optional fields
3+ messages / 2 participants
[nested] [flat]

* Optional fields
@ 2001-01-16 14:57  Timothy_Maguire@hartehanks.com
  0 siblings, 1 reply; 3+ messages in thread

From: Timothy_Maguire@hartehanks.com @ 2001-01-16 14:57 UTC (permalink / raw)
  To: pgsql-php

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.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Optional fields
@ 2001-01-17 07:22  Dan Wilson <phpPgAdmin@acucore.com>
  parent: Timothy_Maguire@hartehanks.com
  0 siblings, 0 replies; 3+ messages in thread

From: Dan Wilson @ 2001-01-17 07:22 UTC (permalink / raw)
  To: Timothy_Maguire@hartehanks.com; 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.
>
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Optional fields
@ 2001-01-17 14:32  Timothy_Maguire@hartehanks.com
  0 siblings, 0 replies; 3+ messages in thread

From: Timothy_Maguire@hartehanks.com @ 2001-01-17 14:32 UTC (permalink / raw)
  To: Dan Wilson <phpPgAdmin@acucore.com>; +Cc: 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.
>
>








^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-01-17 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-16 14:57 Optional fields Timothy_Maguire@hartehanks.com
2001-01-17 07:22 ` Dan Wilson <phpPgAdmin@acucore.com>
2001-01-17 14:32 Re: Optional fields Timothy_Maguire@hartehanks.com

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox