- Mar 26, 2005
- 4,094
- 123
- 106
I have 3 files. 1 HTML file, 1 PHP file and one CSS file.
When I run my index.php my "echo" statements place their output on the upper right of the webpage, but I want them right next to my labels. I want scores output to be placed next to scores, Score Total next to Score Total and so on...
I tried googling for this, but no matter how much I search, the darned thing still tells me my variable is undefined! I am completely lost. I have no idea what I am doing wrong.
Don't worry about the unfinished code for dice rolls. I will deal with that later once I understand how to properly output my results.
index.php
loop_tester.php
main.css
When I run my index.php my "echo" statements place their output on the upper right of the webpage, but I want them right next to my labels. I want scores output to be placed next to scores, Score Total next to Score Total and so on...
I tried googling for this, but no matter how much I search, the darned thing still tells me my variable is undefined! I am completely lost. I have no idea what I am doing wrong.
Don't worry about the unfinished code for dice rolls. I will deal with that later once I understand how to properly output my results.
index.php
Code:
<!DOCTYPE html>
<html>
<head>
<title>Loop Tester</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<?php
$action = filter_input(INPUT_POST, 'action');
if($action == 'process_scores'){
//ECHO "SCORES";
$scores = $_POST['scores'];
//var_dump($scores);
$score_string='';
$score_total=0;
$score_average=0;
foreach($scores as $score){
$score_string.=$score.' ';
$score_total+=$score;
}
echo $score_string . '<br>';
echo $score_total . '<br>';
$score_average = $score_total/3;
echo $score_average . '<br>';
}
else if ($action == 'process_rolls'){
ECHO "ROLLS";
}
/*$rolls = 'number_to_roll';
$sides = 6;
$results = array();
for($i = 0; $i < $rolls; $i++) {
$results[] = rand(1,$sides);
}
echo "Each roll:<ul><li>";
echo implode("</li><li>", $results);
echo "</li></ul>";
$total = array_sum($results);
echo "Max: $total<br>";
echo "Average: ". $total / count($results);*/
include 'loop_tester.php';
?>
</body>
</html>
loop_tester.php
Code:
<!DOCTYPE html>
<html>
<head>
<title>Loop Tester</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<main>
<h1>Loop Tester</h1>
<h2>Process Scores</h2>
<form action="." method="POST">
<input type="hidden" name="action" value="process_scores">
<label>Score 1:</label>
<input type="text" name="scores[]" ><br>
<label>Score 2:</label>
<input type="text" name="scores[]" ><br>
<label>Score 3:</label>
<input type="text" name="scores[]" ><br>
<label> </label>
<input type="submit" value="Process Scores"><br>
<label>Scores:</label>
<span>"<?php echo $score_string; ?>" ></span><br> [b]<!-- WHY THE HECK IS THIS UNDEFINED, AND HOW CAN I GET IT TO SHOW PROPERLY? -->[/b]
<label>Score Total:</label>
<span></span><br>
<label>Average Score:</label>
<span><span><br>
</form>
<h2>Process 1000 Die Rolls</h2>
<form action="." method="post">
<input type="hidden" name="action" value="process_rolls">
<label>Number to Roll:</label>
<select name="number_to_roll"> <!-- If possible, change this to do the same with a php loop-->
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select><br>
<label> </label>
<input type="submit" value="Process Rolls"><br>
<label>Maximum Rolls:</label>
<span></span><br>
<label>Average Rolls:</label>
<span></span><br>
</form>
</main>
</body>
</html>
main.css
Code:
body {
font-family: Arial, Helvetica, sans-serif;
}
main {
width: 450px;
margin: 0 auto;
padding: 1em;
background: white;
border: 2px solid navy;
}
h1 {
margin-top: 0;
color: navy;
}
label {
display: block;
width: 8em;
text-align: right;
margin: 0 0 .5em;
padding: 0 1em;
float: left;
}
input, select {
display: block;
float: left;
margin-bottom: .5em;
margin-top: 0;
}
br {
clear: left;
}