Click to See Complete Forum and Search --> : [RESOLVED] Postgre Query oddity


mith36
08-07-2008, 11:03 AM
Hi,

I'm used to using mysql, but a db I'm working with atm is postgre...

I don't understand why this query works in php on one page and in a sql browser:

$q = "SELECT bwmon as bwmon, ewmon as ewmon, cdate AS cdate, e50 as e50, e10 as e10, e90 as e90 FROM fcst WHERE id='$id' AND source='COORD' ORDER BY cdate DESC LIMIT 1";


but in another page it only works this way

$q = "SELECT bwmon as bwmon, ewmon as ewmon, cdate AS cdate, e50 as e50, e10 as e10, e90 as e90 FROM fcst ORDER BY cdate DESC LIMIT 1";


The difference being the second doesnt have

WHERE id='$id' AND source='COORD'


What is going on? :(

chazzy
08-07-2008, 11:55 AM
you're going to have to be more specific. what's not working about these queries? are you getting an error message, if so what is the error?

mith36
08-07-2008, 12:00 PM
I get an empty array as the results.

It's very odd.

I know it connects to the database okay, but there seems to be an issue with the way I'm wording the "WHERE" segment. Is there something I'm missing about postgre sql syntax here?

NOTE: In a sql client I DO get a result, but in php i get the empty array.

Once I remove the "WHERE"'s I have the array has data in it again.

chazzy
08-07-2008, 12:01 PM
are you sure that you have data that matches id='$id' and source='COORD' ?

mith36
08-07-2008, 12:05 PM
Yes, as I said, it works in a SQL client (navicat). That's why I said it's an oddity and why I'm banging my head against the wall here :P

This is a remote project and the terminal access has been iffy. I'd rather run the query at the terminal, but until the ports on the reverse end are fixed, I can't.

chazzy
08-07-2008, 01:48 PM
can you give a few lines before and after the code, so I can see how exactly you're connecting/issuing the query/parsing the results?

mith36
08-07-2008, 02:21 PM
I rewrote the code and it works. I'm not sure what was wrong, but I'm not wasting any more time trying to find it.

RESOLVED