Jump to content

Sorting Aircraft in Order for Pirep Submition


Alex

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :P;)

Is it a drop down box you are wanting to order the results in?

EDIT: Sorry just looked at the code, and it is.

Link to comment
Share on other sites

	/**
 * 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.

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...