JSHINER Posted January 21, 2008 Share Posted January 21, 2008 With the following: $state = "CA"; $page['listings_state'] = RListing::getResults($db, $state, ($pageNum - 1) * $perPage, $perPage); function getResults($db, $state, $offset, $limit) { $query = 'SELECT listing.id AS id, listing.views AS views, listing.price AS price, listing.type AS type, town.name AS town, town.state AS state, listing.town_id AS town_id FROM listing, town WHERE listing.town_id = town.id AND state = ' . $db->escape($state) . ' ORDER BY views DESC LIMIT 9'; return $db->getArray($query); } I get the following error: "Error in database query. Query was [sELECT listing.id AS id, listing.views AS views, listing.price AS price, listing.type AS type, town.name AS town, town.state AS state, listing.town_id AS town_id FROM listing, town WHERE listing.town_id = town.id AND state = CA ORDER BY views DESC LIMIT 9] and the error returned was [unknown column 'CA' in 'where clause']" Any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/ Share on other sites More sharing options...
adam291086 Posted January 21, 2008 Share Posted January 21, 2008 are you sure the column state has CA in it? Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445154 Share on other sites More sharing options...
pocobueno1388 Posted January 21, 2008 Share Posted January 21, 2008 Lets look at this part of the WHERE clause AND state = ' . $db->escape($state) . ' First off you don't have the variable in quotes. Second you are using aliasing throughout the rest of the query, so why are you not using it for the column "state"? So your query should be changed to $query = "SELECT listing.id AS id, listing.views AS views, listing.price AS price, listing.type AS type, town.name AS town, town.state AS state, listing.town_id AS town_id FROM listing, town WHERE listing.town_id = town.id AND town.state = '".$db->escape($state)."' ORDER BY views DESC LIMIT 9"; Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445157 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Yep, it thinks you are looking for Column name CA and not data in the column. Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445160 Share on other sites More sharing options...
JSHINER Posted January 21, 2008 Author Share Posted January 21, 2008 When I put '".$db->escape($state)."' it now just brings up a blank white page . Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445167 Share on other sites More sharing options...
revraz Posted January 21, 2008 Share Posted January 21, 2008 Did you just copy and paste that one item or his whole line of code? You need the double quotes around the query for it to work. When I put '".$db->escape($state)."' it now just brings up a blank white page . Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445168 Share on other sites More sharing options...
JSHINER Posted January 21, 2008 Author Share Posted January 21, 2008 And those are exactly what I forgot All set. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/87049-solved-need-help-with-a-query/#findComment-445172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.