Forum Moderators: coopster

Message Too Old, No Replies

PHP/ mysql question

scripting

         

sdnative

1:19 am on Dec 4, 2009 (gmt 0)

10+ Year Member



Help! lol

I'm fairly new to php. I am trying to pull information from mysql. I've got it working perfectly, but I've run into trouble while trying to pull more than one set of values from a column in mysql.

ex.

$sql_count=" SELECT * FROM `demo8` where `Residential Styles`!='1)DET' and `Zip Code`='92008' ";

I would like to have it select 3 more Zip Code values being 92009, 92010, 92011

I'm sure it's simple, but I'm drawing a blank.

Thanks in advance!

TheMadScientist

2:27 am on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi sdnative,

Welcome to WebmasterWorld!

You'll need to use OR and group the possibilities:

$sql_count=" SELECT * FROM `demo8` where `Residential Styles`!='1)DET' and (`Zip Code`='92008' OR `Zip Code`='92009' OR `Zip Code`='92010' OR `Zip Code`='92011')";

rocknbil

2:49 am on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you can use sets . . . .

$sql_count="select * from demo8 where `Residential Styles`!='1)DET' and `Zip Code` in (90028,90029,90030)";

You should probably have zip as a numeric format, but might not be able to if you're storing zip +4 (90030-1234).

If zip code is not one of the numeric formats, this will still work. I just tested it and surprised myself, the above query also returned the entry 90030-1234. I didn't think it would. :-)

Doesn't work for this though:

$sql_count="select * from demo8 where `Residential Styles`!='1)DET' and `Zip Code` in (90028,1234)";

Just returns the 90028 one.

Something to note, before you go . . .

$sql_count="select * from . . . .

If you're not using anything from this query and just as a count, this is a pretty high overhead, you're selecting all fields. Do

$sql_count="select count(*) from . . .

and this query will return a single-member array, the total row count.

$total = $row[0];

sdnative

2:54 am on Dec 4, 2009 (gmt 0)

10+ Year Member



SWEET! I did't add my ()

PHP is so frustrating some times, lol

Thanks guys!