←  Problemy

AMXX.pl: Support AMX Mod X i SourceMod

»

PHP
Generator liczb

  • +
  • -
mozor - zdjęcie mozor 05.08.2012

Witam,

znalazłem w internecie taki o to generator liczb.
Chciał bym żeby nie pokazywało liczb po przecinku, jak to zrobić.
Proszę o pomoc.
<?php
if (!$_POST['submit'])
{
//form not submitted, display form
?>
<form action="<?php echo $SERVER['PHP_SELF']; ?>"
method="post">
<br />
This is a DECIMAL random number generator that generates numbers specified by minimum and maximum value.<br />
For example you would like to generate random numbers between 99.75 and 100.25<br />
Example of this generated decimal random number will be 99.85. 100.21, 100.01, 99.98 etc. <br />
All you need is to specify how many random numbers you need, then also the range eg. minimum and maximum values. Fill up the form and <br />
tool will automatically produce the numbers to you. <br />
This tool may contain repeated numbers and if you like uniquely produced numbers, I will create one in the future. <br />
However you can use Excel to provide unique filtering of the produced set of random numbers. <br />
This tool will give two decimal places of the result.
<br /><br />
Given:
<br />
Wpisz ile liczb ma się pokazać <input type="text" name="amount" size="10">
<br />
<br />
Wpisz maksymalną wartość liczby: <input type="text" name="max" size="10">
<br />
<br />
Wpisz minimalną wartość liczby: <input type="text" name="min" size="10">
<br />
<br />
<input type="submit" name="submit" value="Generuj!">
</form>
<br />
<br />
<br />
To narzędzie zostało stworzone przez: <a href="link">.....</a>
<br />
<?php
}
else
{
//form submitted, grab the data from POST
$amount =trim($_POST['amount']);
$max =trim($_POST['max']);
$min =trim($_POST['min']);
//test if it contains some data.
if (((isset($amount)) && !(trim($amount) == "") && !(trim($max) == "") && !(trim($min) == "")) && ((is_numeric($amount)) && (is_numeric($max)) && (is_numeric($min)) && ($max > $min)))
{
//form input is either not empty and is numeric, process values
echo '<h2>Below are the generated decimal random numbers:</h2><br /><br />';
$maxadjusted = $max * 100;
$minadjusted = $min * 100;
$i = 1;
while ($i <= $amount) {
$random =mt_rand($minadjusted,$maxadjusted);
$number =1*  $random;
$i++;
echo round($number,2);
echo '<br />';
}
echo '<br />';
echo '<br />';
echo 'You have set max value to: &nbsp;'.$max;
echo '<br />';
echo 'You have set min value to: &nbsp;'.$min;
echo '<br />';
echo 'Amount of random numbers generated: &nbsp;'.$amount;
echo '<br />';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Try again this tool</a><br />';
}
else
{
//something is wrong with the inputted data
echo 'Please double check inputted data, it seems you either enter a blank data, wrong captcha, inputted a non-numeric value or inputted a value in a maximum field but is actually a minimum than your minimum set value.';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Click here to input data again.</a>';
}
}
?>
Odpowiedz

Gość_21977_* 05.08.2012

O ile dobrze zrozumiałem, to zamień
echo round($number,2);
na
echo round($number);
Odpowiedz

  • +
  • -
mozor - zdjęcie mozor 05.08.2012

Wywala mi wtedy taki błąd.

Parse error: syntax error, unexpected T_ECHO in /virtual/n/i/xxx/losowanie.php on line 55



Gdzie xxx to moja strona
Odpowiedz

  • +
  • -
speedkill - zdjęcie speedkill 05.08.2012

Pokaż kod, jak to zrobiłeś.
Odpowiedz

  • +
  • -
mozor - zdjęcie mozor 06.08.2012

<?php
if (!$_POST['submit'])
{
//form not submitted, display form
?>
<form action="<?php echo $SERVER['PHP_SELF']; ?>"
method="post">
<br />
This is a DECIMAL random number generator that generates numbers specified by minimum and maximum value.<br />
For example you would like to generate random numbers between 99.75 and 100.25<br />
Example of this generated decimal random number will be 99.85. 100.21, 100.01, 99.98 etc. <br />
All you need is to specify how many random numbers you need, then also the range eg. minimum and maximum values. Fill up the form and <br />
tool will automatically produce the numbers to you. <br />
This tool may contain repeated numbers and if you like uniquely produced numbers, I will create one in the future. <br />
However you can use Excel to provide unique filtering of the produced set of random numbers. <br />
This tool will give two decimal places of the result.
<br /><br />
Given:
<br />
Wpisz ile liczb ma się pokazać <input type="text" name="amount" size="10">
<br />
<br />
Wpisz maksymalną wartość liczby: <input type="text" name="max" size="10">
<br />
<br />
Wpisz minimalną wartość liczby: <input type="text" name="min" size="10">
<br />
<br />
<input type="submit" name="submit" value="Generuj!">
</form>
<br />
<br />
<br />
To narzędzie zostało stworzone przez: <a href="link">.....</a>
<br />
<?php
}
else
{
//form submitted, grab the data from POST
$amount =trim($_POST['amount']);
$max =trim($_POST['max']);
$min =trim($_POST['min']);
//test if it contains some data.
if (((isset($amount)) && !(trim($amount) == "") && !(trim($max) == "") && !(trim($min) == "")) && ((is_numeric($amount)) && (is_numeric($max)) && (is_numeric($min)) && ($max > $min)))
{
//form input is either not empty and is numeric, process values
echo '<h2>Below are the generated decimal random numbers:</h2><br /><br />';
$maxadjusted = $max * 100;
$minadjusted = $min * 100;
$i = 1;
while ($i <= $amount) {
$random =mt_rand($minadjusted,$maxadjusted);
$number =1*  $random;
$i++;
echo round ($number);
echo '<br />';
}
echo '<br />';
echo '<br />';
echo 'You have set max value to: &nbsp;'.$max;
echo '<br />';
echo 'You have set min value to: &nbsp;'.$min;
echo '<br />';
echo 'Amount of random numbers generated: &nbsp;'.$amount;
echo '<br />';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Try again this tool</a><br />';
}
else
{
//something is wrong with the inputted data
echo 'Please double check inputted data, it seems you either enter a blank data, wrong captcha, inputted a non-numeric value or inputted a value in a maximum field but is actually a minimum than your minimum set value.';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Click here to input data again.</a>';
}
}
?>


Mógł by mi ktoś to zrobić ?
Użytkownik mozor edytował ten post 06.08.2012 17:54
Odpowiedz

Gość_21977_* 06.08.2012

Pomijając kwestię samego kodu,
<?php
if (!$_POST['submit'])
{
//form not submitted, display form
?>
<form action="<?php echo $SERVER['PHP_SELF']; ?>"
method="post">
<br />
This is a DECIMAL random number generator that generates numbers specified by minimum and maximum value.<br />
For example you would like to generate random numbers between 99.75 and 100.25<br />
Example of this generated decimal random number will be 99.85. 100.21, 100.01, 99.98 etc. <br />
All you need is to specify how many random numbers you need, then also the range eg. minimum and maximum values. Fill up the form and <br />
tool will automatically produce the numbers to you. <br />
This tool may contain repeated numbers and if you like uniquely produced numbers, I will create one in the future. <br />
However you can use Excel to provide unique filtering of the produced set of random numbers. <br />
This tool will give two decimal places of the result.
<br /><br />
Given:
<br />
Wpisz ile liczb ma się pokazać <input type="text" name="amount" size="10">
<br />
<br />
Wpisz maksymalną wartość liczby: <input type="text" name="max" size="10">
<br />
<br />
Wpisz minimalną wartość liczby: <input type="text" name="min" size="10">
<br />
<br />
<input type="submit" name="submit" value="Generuj!">
</form>
<br />
<br />
<br />
To narzędzie zostało stworzone przez: <a href="link">.....</a>
<br />
<?php
}
else
{
//form submitted, grab the data from POST
$amount =trim($_POST['amount']);
$max =trim($_POST['max']);
$min =trim($_POST['min']);
//test if it contains some data.
if (((isset($amount)) && !(trim($amount) == "") && !(trim($max) == "") && !(trim($min) == "")) && ((is_numeric($amount)) && (is_numeric($max)) && (is_numeric($min)) && ($max > $min)))
{
//form input is either not empty and is numeric, process values
echo '<h2>Below are the generated decimal random numbers:</h2><br /><br />';

$i = 1;
while ($i <= $amount) {
$random =mt_rand($min,$max);
$i++;
echo $random;
echo '<br />';
}
echo '<br />';
echo '<br />';
echo 'You have set max value to: &nbsp;'.$max;
echo '<br />';
echo 'You have set min value to: &nbsp;'.$min;
echo '<br />';
echo 'Amount of random numbers generated: &nbsp;'.$amount;
echo '<br />';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Try again this tool</a><br />';
}
else
{
//something is wrong with the inputted data
echo 'Please double check inputted data, it seems you either enter a blank data, wrong captcha, inputted a non-numeric value or inputted a value in a maximum field but is actually a minimum than your minimum set value.';
echo '<br />';
echo '<a href="/decimalrandomnumbergenerator.php">Click here to input data again.</a>';
}
}
?>
Odpowiedz

  • +
  • -
mozor - zdjęcie mozor 06.08.2012

Wielkie dzięki ;]

A mógł byś mi podpowiedzieć jak zrobić żeby te liczby na jakimś tle graficznym się pokazywało?
Odpowiedz

  • +
  • -
ELOS - zdjęcie ELOS 10.08.2012

dodaj backgrounda i ustaw mu divem pozycje.
Odpowiedz