hello new php programmer here, im creating an cms evaluation and i want the value of that evaluation to auto add and divided to a portion percentage ex.(35%) for that evaluation please kindly guide me how the logic.
Add all points with the eva 1 id compute the percentage base on given percent data
currently out put
code :
<?php echo $roweva["evaluation"];?>(<?php echo $roweva["percent"];?>%)
<?php echo $rowpts["points"]; ?> hidden-><?php echo $roweva["maxpts"]; ?>
view :
eva 1 (50%)
5
5
5
eva 2 (50%)
10
10
what i want to get for the output is the addition of all points of that particular evaluation and its percent %, for clear explanation see the example input and ouput below.
ex .
input / get data:
eval 1 50% --> 50%(if all q are max points)
ques1 5/10 -->/10(the maxpoints)
ques2 5/5 --> 3 ques
ques3 5/5
eval 2 50%
ques1 10/10 --> 2 ques
ques2 10/10
out put :
eval 1 = 15 points 37.5% ---(20 max pts & 75% of 50%)
eval 2 = 20 points 50% ---(20 max pts & 100% of 50%)
Related
So I want to get number with Consecutive Numbers like below.
1234567891011121314151617181920212223..............
when i input 10 then output is 1. and so on like below.
10th digit is 1
11th digit is 0
12th digit is 1
13th digit is 1
14th digit is 1
15th digit is 2
16th digit is 1
17th digit is 3
This is my code to make Consecutive Numbers. Its work as i want expected.
<?php
$i=1;
$urut='';
$a = $_GET['button1'];
echo "Your number ", $a, "<br>";
while ($i<=$a){
$urut=$urut.''.$i;
$i++;
}
$pecah = str_split($urut,1);
echo "Urut angka ke ".$a."adalah ". $pecah[$a-1];
?>
But my case is how to get number when Consecutive up to 1 million or more.
I tried that but when set 1 millions or more its load very long time and cant show the result number
You'll probably need to do something like calculating the length of each range of numbers.
For example you know that:
1 through 9 are 1 character
10 through 99 are 2 characters
100 through 999 are 3 characters
And so on
Doing so will allow you to calculate the length of the string up to a certain number.
For example the amount of characters before 1000 can be calculated like so.
9x1 + (99 - 10) x 2 + (999 - 100) x 3
Using this you can distil a formula which allows you to calculate the value for any given number.
This question already has an answer here:
Generate a random number with bias result in PHP
(1 answer)
Closed 5 years ago.
I have the following script:
$domain = ['gmail.com', 'yahoo.com', 'hotmail.com'];
$domain = $domain[mt_rand(0, count($domain) - 1)];
It is possible to set a percentual value for each item coresponding to chances of being chosen.
For example, i want to have 75% chances to have a $domain='gmail.com';.
There are many ways to achieve the desired result.
My method doesn't demand that the total "chances" be 100; you can make your own decision on the value of the highest key.
The basis of my method is that the result ($domain) will be the array value with the lowest key that is not greater than the randomized number ($pick).
Here is an example to give gmail a 75% chance, and give yahoo & hotmail equal chances with the remaining 25%.
*Notice that mt_rand() starts at 1 versus 0 as commented under the question.
$domain_perc=array(
750=>'gmail.com', // between 1 & 750 = 75% chance
875=>'yahoo.com', // between 751 & 875 = 12.5% chance
1000=>'hotmail.com' // between 876 & 1000 = 12.5% chance
);
$pick=mt_rand(1,max(array_keys($domain_perc)));
foreach($domain_perc as $p=>$v){
if($pick<=$p){
$domain=$v;
break;
}
}
Or you can replace the foreach() code block with this one-liner:
$domain=current(array_filter($domain_perc,function($v,$k)use($pick){return $pick<=$k;},ARRAY_FILTER_USE_BOTH));
As for customizing the input array, a simple way of expressing a 50%-25%-25% split would be:
$domain_perc=array(
2=>'gmail.com', // 1 and 2 of 4 = 50% chance
3=>'yahoo.com', // 3 of 4 = 25% chance
4=>'hotmail.com' // 4 of 4 = 25% chance
);
To set up a two-value array with a ~33% -vs- ~66% split:
$domain_perc=array(
1=>'gmail.com', // 1 of 3 = ~33% chance
3=>'yahoo.com' // 2 & 3 of 3 = ~66% chance
);
Imagine that squares in a TicTacToe grid are numbered in a linear fashion from 1 to 9. A player puts an X on the grid by calling a class method:
$game->putX(1, 1); (the method accepts only integers from 0 to 2).
How do I calculate the linear value of the field where X was placed (here the linear value is 5)?
Your help will be much appreciated.
It's actually just x*3 + y+1. Assuming the games state is saved in an array (indexed 1-9, according to your question), your code could look like this:
// the board: examples:
// x 0 1 2 0 0 -> 1
// y 1 1 -> 5
// 0 1 2 3 2 2 -> 9
// 1 4 5 6
// 2 7 8 9
putX ($x, $y) {
$this->state[$x*3+$y+1] = 'X';
}
I have a table that has the following columns and fields:
userid round faceoff username
------------------------------
1 1 2 Kevin
3 1 1 Steve
4 1 3 Jake
9 1 4 Sam
1 2 1 Kevin
9 2 2 Sam
1 3 1 Kevin
The round are the columns and faceoff are the rows. Thus round 1 has a max of faceoff 4, and round 2 has a faceoff max of 2, etc.
I want to display the data on users screens like so (basic HTML):
Round 1 Round 2 Final (round 3)
Steve
Kevin
Kevin
Kevin
Jake
Sam
Sam
Here is what I have so far:
$tor is the array from MySQL, I var_dump() it and everything is there. I'm just having issues with the for loops:
for ($u=0;$u<=$torindex;$u++)
{
for ($r=1;$r<=$torindex+1;$r++)
{
if ($tor[$u]['round'] == $r)
{
for ($f=1;$f<=$torindex+1;$f++)
{
if ($tor[$u]['faceoff'] == $f) $placement[$r][$f] = $tor[$u]['userid'].":".$tor[$u]['username'];
}
}
}
}
Where do I go from here?
For each row in your data table, you can find right row in HTML table to display it using this equation:
rowNum = pow(2, round - 1) + (faceoff - 1) * pow(2, round);
so this should work in MySQL:
SELECT * FROM tournament ORDER BY pow(2, round - 1) + (faceoff - 1) * pow(2, round);
Structure
I have used the Knockout tournament scheduler class by Nicholas Mossor Rathmann for this task in the past with great success. Given teams/players it will calculate the ties and eliminations based on the matches final score.
Output
For CSS/HTML output instead of the GD generated image the class gives you I used One Fork's jQuery & JSON to draw single-elimination tournament bracket with some modifications for IE compatibility.
Sort it by round like you have it and as you cycle through the rows keep track of the current round. If the row's round is not equal to the current round you know to move to the right. You can close and start a div or ul and float them to the left.
http://jsfiddle.net/RxDrd/
I have an internal counter that counts from 0-999999999999.
I would like this to display as a number between 0-9999, then rollover again.
This means:
0 displays as 1
1 displays as 2
9998 displays as 9999
...
9999 displays as 1
10000 displays as 2
...
19999 displays as 1
20000 displays as 2
edit:
1 + $number % 9999 was the answer (Thanks #Brad Christie). My table of expected results is wrong. (Thanks #Tevo D)
$x = 9280293;
$baseNineNineNineNine = $x % 9999;
Use MOD, it will give you the remainder past 9999 (e.g. Any number divided by 9999 can go in N times, with a remainder of Y (you'll end up with Y as a value)
For the numbers you're looking for, you may want to +1 any value you get after the MOD (%), or use 10000
See also the Modulus Operator
Take reminder with 10000, that guarantees the result to be in between 0 and 9999 and rolls over
$result = $int % 10000;
Your table of values doesn't match what you asking for. In the example you are using 9999 result values (1-9999) for 10000 input values. In the text you are saying 10000 output values (0-9999).
Here is what I think you are really asking for. This algorithm will output 1-9999 and then roll over to 1 again.
In other words, this solution will provide a four digit non-zero value:
$result = $int % 9999 + 1;
The output will NOT match your example, as your example has it rolling over every 10000 values, not 9999. Here is the output:
input output
0 1
1 2
.... ....
9997 9998
9998 9999
9999 1 <--- 9999 * 1
10000 2
.... ....
19996 9998
19997 9999
19998 1 <--- 9999 * 2
19999 2
.... ....
19995 9998
19996 9999
19997 1 <--- 9999 * 3
19998 2
.... ....