Moderators mark1million Posted June 8, 2011 Moderators Report Share Posted June 8, 2011 Hi, I am writing a module to only display unique ICAO aircraft, this is what i have, /** * Get an aircraft by unique name */ public static function getAircraftByName1() { $sql = 'SELECT DISTINCT icao, fullname, weight, cruise, maxpax, maxcargo, imagelink, downloadlink FROM ' . TABLE_PREFIX . 'aircraft WHERE `enabled` = 1 '; return DB::get_results($sql); } That works fine, but when i try to add the range nothing is displayed so if i do, /** * Get an aircraft by unique name */ public static function getAircraftByName1() { $sql = 'SELECT DISTINCT icao, fullname, range, weight, cruise, maxpax, maxcargo, imagelink, downloadlink FROM ' . TABLE_PREFIX . 'aircraft WHERE `enabled` = 1 '; return DB::get_results($sql); } Not sure why but any help would be appreciated Thanks. Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted June 8, 2011 Report Share Posted June 8, 2011 try changing the field name like this /** * Get an aircraft by unique name */ public static function getAircraftByName1() { $sql = 'SELECT DISTINCT icao, fullname, range as acrange, weight, cruise, maxpax, maxcargo, imagelink, downloadlink FROM ' . TABLE_PREFIX . 'aircraft WHERE `enabled` = 1 '; return DB::get_results($sql); } see if that works Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted June 8, 2011 Administrators Report Share Posted June 8, 2011 A couple things: DISTINCT icao, fullname, range, weight ... That looks for ALL of those fields as DISTINCT, you'd want to do DISTINCT(icao). Aside from that, you might be looking to use GROUP BY instead of DISTINCT edit: nevermind on the GROUP BY edit: I see the problem. Enclose field names with `: $sql = 'SELECT DISTINCT `icao`, `fullname`, `range`, `weight`, `cruise`, `maxpax`, `maxcargo`, `imagelink`, `downloadlink` FROM `' . TABLE_PREFIX . 'aircraft` WHERE `enabled` = 1 '; Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted June 8, 2011 Author Moderators Report Share Posted June 8, 2011 Thanks Jeff and Nabeel for your help. Quote Link to comment 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.