PHP - Percentage Help
I have made a 'health bar' for a simple browser game i have been working on.
I want to use a background image to fill the health bar, so if for example, the player had full health, the health bar image width would be 100%
is it possible to say set, the characters max health and the characters actual health and work it out as a percentage so i can stretch the image width as far as it needs to go?
sorry if i haven't been too clear, my understanding of maths is not so good.
Thanks for any tips.
Similar Tutorialshey guys is it possible to have an output that will echo a percentage between 2 tables? like students vs detentions would give like 45%.. Hi,
I basically want a function that takes a parameter which is a percentage chance of the functioning returning true.
A user can move from tier 1->10 and at tier 1 there's a 70% chance to move to tier 2, from tier 2 there's a slightly less chance to move up, and so on.
I tried with the following piece of code:
public function rollTheDice($winnerPercentage) { $number = rand(1, 100); if ($number <= $winnerPercentage) return true; return false; }The above code makes logical sense to me: 1. Pick a random number between 1 and 100. 2. If that number is less than or equal to the percentage, then we passed (example, if the random number is less than or equal to 70.. there must be a 70% chance of this?) This however does not seem to work, in fact it appears that when simulating a roll, 70% fails at the very first step (where there is a 70% chance of winning..) To actually make it to tier 10, has yet to be accomplished, so by simulating this with unlimited attempts for 120 seconds straight doesn't seem to "win". I tried (just for fun) and change the if-statement so: if ($number >= $winnerPercentage) This seems to be working quite well, as the simulator quickly reaches tier 10 this way. Any suggestions to code changes, or can someone explain why it is working way better when exchanging less than with greater than? I have a scratch ticket system I made, and this code generates if a user will win or not. Code: [Select] $card1 = rand(1,5); $card2 = rand(1,5); if($card1 == "1" && $card2 == "1"){ //I WON!!! do my queries here/etc }else{ //Failed } Okay, now how can I make it so I can set it up so I can change it to 5% of winning, 10% of winning, 15% of winning, 20% of winning/etc so on? instead of just a random count function? Hello In my query i have x activities, then i have the count of how many still to be executed, i need to get the percentage of the total executed I mean i have 200 activities, 20 have been executed, so i want to have 10% done My query is this one but missing the percentage field SELECT COUNT(*) AS total, IFNULL(SUM(CASE WHEN (t1.dataPrevista >= CURDATE() OR ae.Fim <= CURDATE()) THEN 1 ELSE 0 END),0) AS exec FROM atividades AS t1 INNER JOIN anosescolares AS ae ON (t1.`idAnoEscolar` = ae.idAnoEscolar) WHERE ae.Estado = 1; any help? Hmm, not quite sure how to do this one... If i have lots of strings saved in a mysql table and one was... "A man and a dog took a nice walk in the park" If a user then wanted to input another string into the table, but i wanted to check the new string was at least 5% different to all other in the table, how would i about doing this? Is it possible to do this via mysql, or would i have to pull out all the strings into a php array and process it that way... somehow? This topic has been moved quickly to PHP Regex because I need to go to work instead of lurking phpfreaks. http://www.phpfreaks.com/forums/index.php?topic=359460.0 hello guys, i need a help from u. from past 1 week , i am searching for it. may be it is simple query for you . in my project, i am uploading a file, for example 5mb of audio file, while uploading i need to display a progress bar along with percentage of how much it is uploaded to server ( as it works in google chrome browser). i tried several codes by searching in google . No code is working. i can able to display only loader.gif image not the status bar with percentage. so pls guys if you have these codes, pls share it . Hi all,
I am building a random prize assigner function based on weighted percentages.
I am able to assign a basic true/false weighting but am struggling to form a way of selecting an array based prize based on the win rate.
Heres my current code:
function selectPrize() { $prizes = array( 0 => array( 'name' => 'Top Prize', 'rate' => 50 ), 1 => array( 'name' => 'Middle Prize', 'rate' => 30 ), 2 => array( 'name' => 'Bottom Prize', 'rate' => 20 ), ); // oops } selectPrize();Could somebody please give me pointers on how i could approach this? Thanks. Edited by biggieuk, 19 June 2014 - 05:14 AM. I'm making a login area for the hotels in a booking system, where they enter their hotels' information, policy, and room rates but I want to make the room rates when it appears for clients, it appears with a percentage (commission) added to what the Hotel representative will enter So what's better? it should be added in the admin area of the hotels and gets saved in the database with the commission or I should add it in the booking form so the code grab the rate from the database, multiply it by the percentage and echo the result? |