You can't do "WHERE Industry = 1, 2, 3" unless that's something you can
do in MySQL but not the other DB's I've used.

What you CAN do is us "IN":


WHERE Industry IN (1, 2, 3)

Or..

WHERE Industry IN ('1','2','3')


"IN" basically does a Industry = 1 OR Industry = 2 OR Industry = 3 type
thing.

If there's a more efficient way to do your query, I'd recommend it.
"IN" or even the multiple OR statements can be very intensive on a
database with a high load or tons of rows.  But it's definitely the
right answer for some solutions.

If you have 8 categories for Industry and you're doing IN (1, 2, 3, 4,
5) then you might consider doing a <> 6, <> 7, <> 8 type thing (I'm
guessing you can do "NOT IN (6, 7, 8)", just never done it).   The fewer
things you're checking in your WHERE clause, the less work your DB
server has to do.

HTH

-TG

> -----Original Message-----
> From: Stuart Felenstein [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, November 13, 2004 1:16 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Help: Database Search
> 
> 
> I've changed my logic around but still running into a
> sql query error.
> I've tried a number of things with no success.  Here
> is the error that returns on POST:
> 
> SELECT PostStart, JobTitle, Industry, LocationState,
> VendorID FROM VendorJobs WHERE (VendorJobs.Industry =
> ''1','2','3''Query failed: You have an error in your
> SQL syntax. Check the manual that corresponds to your
> MySQL server version for the right syntax to use near
> '1','2','3''' at line 2 . 
> 
> Here is the relevant code:
> 
> $Ind = $HTTP_POST_VARS['Ind'];
> if (count($Ind) > 0 AND is_array($Ind)) {
>     $Ind = "'".implode("','", $Ind)."'";
> }
> $sql = "SELECT PostStart, JobTitle, Industry,
> LocationState, VendorID
>         FROM VendorJobs";
> //if ($Ind)
> $sql .= " WHERE (VendorJobs.Industry = '$Ind'";
> 
> I'm not trying to be a pain here.  Either I'm not
> catching a syntax error or something else.
> 
> Stuart

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to