Re: Sql/PHP question
| From: | CPT John W. Holmes | Date: | Wed, 16 Apr 2003 19:18:55 +0000 |
| Subject: | Re: Sql/PHP question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144183@lists.php.net to get a copy of this message | ||
> I had the values set for $department and $location set with the quotes.
> I removed that after my posting realizing the mess I was creating.
>
> This could get pretty complex. I just noticed that what happens if all
> is selected for both departments and locations. then you can't have
> where in the query, also the and will give me a fit too if I only
> select one.
>
> I can do it, it will just take some planning, and I will have to be
> careful if I add any more selections.
Yeah, it's certainly possible. Just realizing that you can use PHP to
"create" your query is a step in the right direction. Now you just need to
work out the logic.
I usually do something like this:
$report['where'] = " 1 ";
if($condition1)
{ $report['where'] .= " and column = 'value' "; }
if($condition2)
{ $report['where'] .= " and column2 = 'value2' "; }
$query = "select * from table where {$report['where']}";
Hope that helps. The other method works, also, but sometimes this one is
just easier.
---John Holmes...