Alex Posted July 28, 2011 Report Share Posted July 28, 2011 I want to sort my airlines aircraft in ascending order when the pilot comes to choose his aircraft for submission of a pirep. I have tried two ways so far. in local config i did this. /* Sort the aircraft by order*/ Config::Set('AIRCRAFT_ORDER_BY', 'name ASC'); That doesn't appear to work. I also went into my mysql db and went into operations changing the alter table order from "id" to "name", but that doesnt seems to work either. My php code on the pirep submit tpl is as follows, i wonder if someone could point me in the correct direction. <div align="center"> <select name="aircraft" id="aircraft"> <option value="">Select the aircraft of this flight</option> <?php foreach($allaircraft as $aircraft) { $sel = ($_POST['aircraft'] == $aircraft->name || $bid->registration == $aircraft->registration)?'selected':''; echo '<option value="'.$aircraft->id.'" '.$sel.'>'.$aircraft->name.' - '.$aircraft->registration.'</option>'; } ?> </select> </div> Thanks Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 28, 2011 Report Share Posted July 28, 2011 I think you would need to add an "ORDER BY ****" to the MySQL query that's pulling the aircraft data from the database table. Not sure which Data.class.php file the correct query is located in though, one of the files that are located in the /core/common folder. More on ORDER BY here: http://www.w3schools.com/php/php_mysql_order_by.asp Quote Link to comment Share on other sites More sharing options...
Alex Posted July 28, 2011 Author Report Share Posted July 28, 2011 If thats the case i'm wondering if its the operationsdata.class.php that would need the order_by, i'm sure there must be an easier way! Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 28, 2011 Report Share Posted July 28, 2011 If thats the case i'm wondering if its the operationsdata.class.php that would need the order_by, i'm sure there must be an easier way! It would be easy as hell if you knew which query to add it to Is it a drop down box you are wanting to order the results in? EDIT: Sorry just looked at the code, and it is. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 28, 2011 Report Share Posted July 28, 2011 Sorry didn't work 1 Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 28, 2011 Report Share Posted July 28, 2011 /** * Get an aircraft according to registration */ public static function getAircraftByReg($registration) { $registration = DB::escape(strtoupper($registration)); $sql = 'SELECT * FROM ' . TABLE_PREFIX .'aircraft ORDER BY name ASC WHERE `registration`=\''.$registration.'\''; return DB::get_row($sql); } This is what I've just tried and it works, I added the ORDER BY to the query above, which is in the OperationsData.class.php file. Quote Link to comment Share on other sites More sharing options...
Alex Posted July 28, 2011 Author Report Share Posted July 28, 2011 Thanks Stuart, mine was almost but not quite the same, but it's working now. Your a star 1 Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 28, 2011 Report Share Posted July 28, 2011 No worries mate, glad to have helped 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.