Jump to content

SQL Help [SOLVED]


mark1million

Recommended Posts

  • Moderators

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.

Link to comment
Share on other sites

Guest lorathon

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

Link to comment
Share on other sites

  • Administrators

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 ';

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...