avdesigns Posted February 22, 2013 Report Share Posted February 22, 2013 Hello, I'm wondering if there is some code I can use to get the percentage the pilot has completed towards there next rank? Thanks Quote Link to comment Share on other sites More sharing options...
Jon Posted February 22, 2013 Report Share Posted February 22, 2013 Not rocket science to do I guess, just need to do some simple work with a few variables: current hours/no of hours required * 100. I guess you can then put it in a progress bar or something if you really wanted to. Not got time right now, but I'll do a quick version for you in the morning if you want. Jon Quote Link to comment Share on other sites More sharing options...
avdesigns Posted February 22, 2013 Author Report Share Posted February 22, 2013 I know the formula im just trying to work out the code for it Quote Link to comment Share on other sites More sharing options...
Jon Posted February 22, 2013 Report Share Posted February 22, 2013 Something like this then? <?php $percentage = ($pilot_hours/$nextrank->minhours) * 100; echo $percentage; ?> Quote Link to comment Share on other sites More sharing options...
avdesigns Posted February 22, 2013 Author Report Share Posted February 22, 2013 Yeah that works just swapped the pilot hours and ranks. Thanks! Quote Link to comment Share on other sites More sharing options...
in2tech Posted May 16, 2015 Report Share Posted May 16, 2015 I want to have a progress bar for each pilot to next rank! Like this: http://screencast.com/t/HYPoTYLP4az How do I accomplish this? I have the % Complete code for Live Flights like this: http://screencast.com/t/nE0bLsOCF Thanks for your help! Quote Link to comment Share on other sites More sharing options...
alpyeni1 Posted May 16, 2015 Report Share Posted May 16, 2015 I want to have a progress bar for each pilot to next rank! Like this: http://screencast.com/t/HYPoTYLP4az How do I accomplish this? I have the % Complete code for Live Flights like this: http://screencast.com/t/nE0bLsOCF Thanks for your help! Hey, I am writed something for you. I'm sure it's working with bootstrap progress bar. You can try another progress bar styles. Remember to change <div class="here"> Preview: http://i.hizliresim.com/b5kQ4Z.jpg <?php // Code by Alp Yeni $percentage = ($pilot_hours/$nextrank->minhours) * 100; //Calculate percentage to next rank. $round = round($percentage); // Round percentage because xxx.x% is not good for CSS. echo '<div class="progress">'; // Create progress bar echo "<div class='progress-bar' role='progressbar' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100' style='width: ", $round, "%'></div>"; // Progress bar inner echo '<span class="sr-only">' .$round. '% Complete</span>'; // Progress bar percentage echo '</div>'; //close inner echo '</div>'; // Close percentage bar ?> For more bootstrap progress-bar styles: http://getbootstrap....nents/#progress Thanks! Quote Link to comment Share on other sites More sharing options...
in2tech Posted May 16, 2015 Report Share Posted May 16, 2015 Alright, I am a little bit confused, actually really confused. I think I have part of it working but I am unsure if it is percentage to next rank or final rank (which wouldn't make since, as i want it to be to next rank in line for the pilot). A few things I am going to try to explain, I hope. Here is the code from above: <?php // Code by Alp Yeni $percentage = ($pilot_hours/$nextrank->minhours) * 100; //Calculate percentage to next rank. $round = round($percentage); // Round percentage because xxx.x% is not good for CSS. echo '<div class="progress">'; // Create progress bar echo "<div class='progress-bar' role='progressbar' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100' style='width: ", $round, "%'></div>"; // Progress bar inner echo '<span class="sr-only">' .$round. '% Complete</span>'; // Progress bar percentage echo '</div>'; //close inner echo '</div>'; // Close percentage bar ?> Than I used my acarsmap.tpl styling in my style sheet, and adjusted it for his code: .progress { border: 1px solid #000000; border-radius: 5px; width: 150px; margin: 0px 0px 0px 0px; padding: 1px; float: middle; background: #f2f2f2; } .progress-bar { background-color: #FF0000; height: 10px; vertical-align:right; } It appears to be working but I am not completely sure. Here are some example screen shots: http://screencast.com/t/VOb4gils2sOL http://screencast.com/t/qLGqSvmsX And than me as admin which I gave myself the max hours to get me to the highest rank as a test, and I get this error because i am at the max rank: http://screencast.com/t/yURELrCZH And of course a pilot that is a new hire it states 0% which is kinda confusing to me as shouldn't it state a percentage to next rank. New pilot no hours: http://screencast.com/t/neT0yhbY Also want it to state you have whatever % to next rank and show the rank in words, whatever the next rank is! Quote Link to comment Share on other sites More sharing options...
in2tech Posted May 17, 2015 Report Share Posted May 17, 2015 Not exactly what I was thinking about but it will work: http://screencast.com/t/n2uNhCxnt6 And now how to fix the error when a pilot reaches the max rank: http://screencast.com/t/yURELrCZH Quote Link to comment Share on other sites More sharing options...
Sava Posted May 17, 2015 Report Share Posted May 17, 2015 I really think the current code could be done better, as it is now showing the % required in total. To better explain, here is an example. Think of a rank structure like this: Rank1 = 0-10h Rank2 = 10-20h Rank3 = 20-30h If I have 15h now, I am 50% on my way to the next rank, Rank3. Correct? (20-10=10h, 15-10=5h, and 5 is a half of 10) But, judging by your code, it would tell me I am 15/20*100 = 75% on my way to the rank. I mean, both ways are technically correct, but I think my way of thinking is a bit better <?php $get_rank_information = RanksData::getRankName(Auth::$userinfo->rank); $current_mh = $get_rank_information->minhours; $difference = $nextrank->minhours - $current_mh; //hours between 2 ranks $hours_in_rank = $pilot_hours - $get_rank_information->minhours; $percent = round(((100 * $hours_in_rank)/$difference)); ?> And you'll probably need to place this in RanksData.class.php public static function getRankName($rank) { $rank = DB::escape($rank); $sql = "SELECT * FROM phpvms_ranks WHERE rank='$rank'"; return DB::get_row($sql); } In the end, I might be wrong, really late here...if that's the case, I'll just edit this in the morning not to confuse people Quote Link to comment Share on other sites More sharing options...
in2tech Posted May 17, 2015 Report Share Posted May 17, 2015 Yeah your right what I have is not working right. What I originally wanted was the "You have 87 hours left until your promotion to Second Officer" to show a progress bar, not the percentage thing I ended up with Quote Link to comment Share on other sites More sharing options...
Sava Posted May 18, 2015 Report Share Posted May 18, 2015 In that case $pilothours-$nextrank->minhours should work correctly Quote Link to comment Share on other sites More sharing options...
in2tech Posted May 18, 2015 Report Share Posted May 18, 2015 I have this in the profile main file: <div class="progress"> <div class="progress-bar"> <div style="width: $pilothours-$nextrank->minhours </div> </div> </div> and this in the css: .progress { border: 1px solid #000000; border-radius: 5px; width: 300px; margin: 0px 0px 0px 350px; padding: 1px 1px 1px 25px; float: middle; background: #f2f2f2; } .progress-bar { background-color: #FF0000; height: 10px; vertical-align:right; } http://screencast.com/t/AMPGjba4II Notice it is set to 50 hours so the progress bar should be half way and starting from the left not the right! It showing a progress bar but it is backwards and does not change when I change the pilot hours. And alignment in my css needs work which I know, but I can't get it to work right Thanks for your help. I appreciate it! Quote Link to comment Share on other sites More sharing options...
Sava Posted May 19, 2015 Report Share Posted May 19, 2015 Really late here, and I am very tired. Just taken a rough look at this, and spotted one obvious error for now. Instead of <div style="width: $pilothours-$nextrank->minhours </div> Try <div style="width: <?php echo round($pilothours-$nextrank->minhours); ?>%"></div> if there is anything else that is making an issue, I'll try and help out tomorrow Quote Link to comment Share on other sites More sharing options...
in2tech Posted July 9, 2015 Report Share Posted July 9, 2015 Sava or anyone else, I am still trying to do this. Any Ideas how to accomplish this with a progress bar from first rank to highest rank? http://screencast.com/t/HYPoTYLP4az Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted July 12, 2015 Moderators Report Share Posted July 12, 2015 A good atlernative way (if you can't do it using css etc) would be to create different images with the progress bar loading and call them based on a specific percentage. For example, if the pilot is on the 50%, you will call the "progress/50.png" etc. Quote Link to comment Share on other sites More sharing options...
magicflyer Posted July 14, 2015 Report Share Posted July 14, 2015 There's a much easier way to have progress bars, thanks to HTML 5 and that is....<progress value="0.5"></progress> where value=X refers to a number between 0.0 (0%) and 1.0 (100%) You can even theme it as you wish: https://css-tricks.com/html5-progress-element/ Quote Link to comment Share on other sites More sharing options...
in2tech Posted July 15, 2015 Report Share Posted July 15, 2015 I have the progress bar working for percentage to rank, what I don't know how to do is the complete range of ranks, from the beginning rank to the ending rank and showing a progress bar as pilots go through the entire rank range (or whatever rank they receive and stop at) to the last rank. I have this and its working properly, as far as the correct percentage to next rank: It's 100 hours to the next rank so the test pilot is at 27% (or 27 hours) of 100 and has 73% (or 73 hours) of 100 to the next rank. And it works. http://screencast.com/t/8NDkNJxc49p Thanks everyone for your help! 1 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.