View Full Version : Question on checking ranks based off hours

05-10-2008, 10:31 PM

What I am trying to do is have the user input rank and flight hours required to obtain that rank. I have created a table for it and set a couple of rows in there.

user inputs
rank in one column and hours in another under the table ranks.


Rank Hours
Pilot 0
Co-Pilot 50
master pilot 100

and so on,

So What I am trying to write is a section of code to take the pilot hours and match it to the hours in the ranks and out put the rank they should be.

I had it as an if statement but I have to hard code each rank and requirement of hours, in which someone has to have some type of php knowledge to change the ranks and requirements.


05-11-2008, 09:31 AM
what you could do is hold your ranks in a "ranks" table




insert all your ranks in the rank name column and give each a qualifying value Now in your form you could add a dynamic drop down displaying the ranks but the values of the <option tags would be the rank_value (the rank_value column could act as your unique key in your db)

now when you key the rank and hours in your form you could do some javascript jiggery pokery and simply display the correct dropdown value

05-11-2008, 11:49 AM
Thanks for the reply
so if I get this correct, it would be a list(select) box, though javascript would match required hours and the pilots actual hours.

My thought is to echo the rank on say a profile, I dont think I am clearly asking this question :confused:

This is the manual code that I have right now,

But I want the $rank to be pulled out of a database and
the hours to come from a db; 0, 50, 100.

<?php $total_hours = $hours.':'.$mins;

if($total_hours ==0){
$rank = 'Pilot';

else if ($total_hours >=1 and $total_hours < 50) {
$rank = 'Flight Officer';

else if($total_hours >=50 and $total_hours < 100){
$rank = 'First Officer';

else if($total_hours >=100 and $total_hours < 200){
$rank = 'Captain';


else if($total_hours >=200 and $total_hours< 500){
$rank = 'Senior Captain';


else if($total_hours >=500 ){
$rank = 'Master Pilot';

echo $rank ?>