[100c]Simple equation page

0010111

New Member
Messages
58
Reaction score
0
Points
0
this image should explain it.
ratio_eq.png

input is how the page should look and the equation is well... how the input should be used. HTML/JS is prefered, PHP is you must. 15c if you tried. 100c for the one i like.
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
well since I don't know where you are getting the input from, I'll just create those variables.

PHP:
<?php
//Define Variables
$fileSize = "";
$uploaded = "";
$downloaded = "";
$finalRatio = "0";

//Math
$totalDown = $fileSize + $downloaded;
$finalRatio = $uploaded / $totalDown;

//Displays the values (optional)
echo $totalDown;
echo "<br />";
echo $finalRatio;
?>
 

0010111

New Member
Messages
58
Reaction score
0
Points
0
well since I don't know where you are getting the input from, I'll just create those variables.

PHP:
<?php
//Define Variables
$fileSize = "";
$uploaded = "";
$downloaded = "";
$finalRatio = "0";

//Math
$totalDown = $fileSize + $downloaded;
$finalRatio = $uploaded / $totalDown;

//Displays the values (optional)
echo $totalDown;
echo "<br />";
echo $finalRatio;
?>
i keep getting this:
Warning: Division by zero in /home/o111011/public_html/r/equation.php on line 10

i changed "
$finalRatio = "0";" to "$finalRatio = "1";" but that made no difference.

also, i was hoping the user would input the data. hence '[input]'
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
PHP:
<?php
if(isset($_POST) {
//Define Variables
$fileSize = "$_POST['fileSize']";
$uploaded = "$_POST['uploaded']";
$downloaded = "$_POST['downloaded']";
$finalRatio = "1";

//Math
$totalDown = $fileSize + $downloaded;
$finalRatio = $uploaded / $totalDown;

//Displays the values (optional)
echo $totalDown;
echo "<br />";
echo $finalRatio;
}
?>

HTML:
<form action="index.php" method="post">
File Size:  <input type="text" name="fileSize" />
Uploaded: <input type="text" name="uploaded" />
Downloaded: <input type="text" name="downloaded" />
<input type="submit" value="Submit" />
<input type="hidden" name="action" value="login" />
</form>

here is what I came up with, save it as a .php and make sure the form redirects to itself; also this does not prevent users from placing in an alphabetical character, therefor the equation will screw up; but rite now I'm too lazy to implement one
 
Last edited:

0010111

New Member
Messages
58
Reaction score
0
Points
0
@Diabolo: the html works fine, correct me if i am wrong but it measures in MB ? can it identify MB/GB/TB ? also:
Parse error: syntax error, unexpected T_VARIABLE in /home/o111011/public_html/r/eq.php on line 4
code hasn't changed.
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
the script doesn't define what it measures it in; you can interpret it any way you want; ie
if you want it as bytes

the would put 100 bytes for 1 MB, I think
 

tttony

Member
Messages
147
Reaction score
0
Points
16
just one tip:

dont use variables into double quotes:

PHP:
$fileSize = "$_POST['fileSize']";
$uploaded = "$_POST['uploaded']";
$downloaded = "$_POST['downloaded']";
$finalRatio = "1";

like this its better:

PHP:
$fileSize = $_POST['fileSize'];
$uploaded = $_POST['uploaded'];
$downloaded = $_POST['downloaded'];
$finalRatio = 1; // <-- now its evaluate as integer
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
thank you tttony
Edit:
<?php
//Define Math Function
function doMath($fileSize, $uploaded, $downloaded) {
$totalDown = $fileSize + $downloaded;
$finalRatio = $uploaded / $totalDown;
}

if(isset($_POST) {
//Define Variables
$fileSize = $_POST['fileSize'];
$uploaded = $_POST['uploaded'];
$downloaded = $_POST['downloaded'];
$finalRatio = 1;

//Checks
if(is_numeric($fileSize) == FALSE){
$error = "Please enter a numeric value for File Size.";
}
if(is_numeric($uploaded) == FALSE){
$error = "Please enter a numeric value for Uploaded.";
}
if(is_numeric($downloaded) == FALSE){
$error = "Please enter a numeric value for Downloaded.";
}
if((isset($_POST) AND (is_numeric($downloaded)){
doMath($fileSize, $uploaded, $downloaded);
}

//Displays the values (optional)
echo $totalDown;
echo "<br />";
echo $finalRatio;
}
?>

<form action="index.php" method="post"> <!-- this is index.php -->
File Size: <input type="text" name="fileSize" />
Uploaded: <input type="text" name="uploaded" />
Downloaded: <input type="text" name="downloaded" />
<input type="submit" value="Submit" />
<input type="hidden" name="action" value="login" />
</form>



not fully done, few bugs but busy
 
Last edited:
Top