----- Original Message ----- 
From: "Stuart Felenstein" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 14, 2004 12:30 PM
Subject: Conditonal where


> Question - I'm creating a dynamic query (using PHP)
> but my question I think is more related to mysql
> syntax.
> Right now I have these statements:
>
> <?php
> $sql .= " SELECT PostStart, JobTitle, Industry,
> LocationState, VendorID FROM VendorJobs";
>
> if ($s_Ind){
> $sql .= " WHERE VendorJobs.Industry IN ($s_Ind)";
> }
>
> if ($s_State){
> $sql .= " AND VendorJobs.LocationState IN ($s_State)";
> }
>
> What I think I need is some kind of default "WHERE" in
> the first statement.  Both Ind and State are
> conditional based on whether the user input anything.
> Right now they would be forced to at least choose the
> Ind.  So instead of the $s_Ind have a "WHERE" it
> should be an "AND" .
>
> ??Any thoughts / ideas.
>
No offense, Stuart, but I really can't make out what you are asking; the
question is bordering on incoherent. Could you please rephrase and make it
clearer what you mean by a "default WHERE"?

By the way, I don't know if any of this will help but I just want to throw
out some generalities that may help bring the question into focus for you.

The first thing you should know is that a WHERE is ALREADY a conditional
statement. For example, when you say 'WHERE VendorJobs.Industry in
($s_Ind)", you are telling the database manager that you only want to see a
row in the table *IF* the value of the VendorJobs.Industry column on that
row is that same as one of the ones in the $s_Ind list.

Is there any particular reason why you are separating each WHERE condition
into parts? For example, there is nothing that would prevent you from having
this:
 $sql .= " WHERE VendorJobs.Industry IN ($s_Ind) AND
VendorJobs.LocationState IN ($s_State)";

I'm not saying it's better or worse to concatenate the different conditions
together; I'm just saying it might be more convenient for you if they were
together. Or not.

Rhino


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to