Do while loop not looping in php
I've been working a loop that repeats incrementally, while displaying the kelvin and fahrenheit counterparts in a table. I'm using a do while loop to do so, however the function does not loop, and does not start on the correct number from the form.
The code I've done so far is:
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<?php
$a = 1;
if ($_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
} while ($x >= $end);
}
?>
<?php
if ($a != 1) {
?>
<table>
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<tr>
<th>
<?php
echo "$x degrees <br />";
?>
</th>
<th>
<?php
echo "$y degrees <br />";
?>
</th>
<th>
<?php
echo "$z degrees <br />";
?>
</th>
</tr>
</table>
<?php
}
?>
</body>
Would I have to include while loops in the echo part of the table for it to loop? And how would I be able to have the loop start on the same number as the form?
php html
add a comment |
I've been working a loop that repeats incrementally, while displaying the kelvin and fahrenheit counterparts in a table. I'm using a do while loop to do so, however the function does not loop, and does not start on the correct number from the form.
The code I've done so far is:
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<?php
$a = 1;
if ($_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
} while ($x >= $end);
}
?>
<?php
if ($a != 1) {
?>
<table>
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<tr>
<th>
<?php
echo "$x degrees <br />";
?>
</th>
<th>
<?php
echo "$y degrees <br />";
?>
</th>
<th>
<?php
echo "$z degrees <br />";
?>
</th>
</tr>
</table>
<?php
}
?>
</body>
Would I have to include while loops in the echo part of the table for it to loop? And how would I be able to have the loop start on the same number as the form?
php html
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07
add a comment |
I've been working a loop that repeats incrementally, while displaying the kelvin and fahrenheit counterparts in a table. I'm using a do while loop to do so, however the function does not loop, and does not start on the correct number from the form.
The code I've done so far is:
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<?php
$a = 1;
if ($_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
} while ($x >= $end);
}
?>
<?php
if ($a != 1) {
?>
<table>
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<tr>
<th>
<?php
echo "$x degrees <br />";
?>
</th>
<th>
<?php
echo "$y degrees <br />";
?>
</th>
<th>
<?php
echo "$z degrees <br />";
?>
</th>
</tr>
</table>
<?php
}
?>
</body>
Would I have to include while loops in the echo part of the table for it to loop? And how would I be able to have the loop start on the same number as the form?
php html
I've been working a loop that repeats incrementally, while displaying the kelvin and fahrenheit counterparts in a table. I'm using a do while loop to do so, however the function does not loop, and does not start on the correct number from the form.
The code I've done so far is:
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<?php
$a = 1;
if ($_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
} while ($x >= $end);
}
?>
<?php
if ($a != 1) {
?>
<table>
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<tr>
<th>
<?php
echo "$x degrees <br />";
?>
</th>
<th>
<?php
echo "$y degrees <br />";
?>
</th>
<th>
<?php
echo "$z degrees <br />";
?>
</th>
</tr>
</table>
<?php
}
?>
</body>
Would I have to include while loops in the echo part of the table for it to loop? And how would I be able to have the loop start on the same number as the form?
php html
php html
asked Nov 16 '18 at 5:01
LoganLogan
12
12
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07
add a comment |
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07
add a comment |
1 Answer
1
active
oldest
votes
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331727%2fdo-while-loop-not-looping-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>
add a comment |
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>
add a comment |
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>
is it you need?
<body>
<form action="" method="post">
Start temperature in degrees:<input type="text" name="start"></input><br />
End temperature in degrees:<input type="text" name="end"></input><br />
How should the list be incremented?:<input type="text" name="inc"></input><br />
<input type="submit" name="sub" value="Submit"></input><br />
</form>
<table >
<tr>
<th>Celsius</th>
<th>Kelvin</th>
<th>Fahrenheit</th>
</tr>
<?php
$a = 1;
if (isset($_POST['sub']) && $_POST['sub']) {
$a = 0;
$start = $_POST['start'];
$end = $_POST['end'];
$inc = $_POST['inc'];
$x = $start;
do {
$x = $x + $inc;
$y = $x + 273;
$z = (1.8 * $x) + 32;
?>
<?php
if ($a != 1) {
?>
<tr>
<th><?php echo "$x degrees <br />"; ?></th>
<th><?php echo "$y degrees <br />"; ?></th>
<th><?php echo "$z degrees <br />";?></th>
</tr>
<?php
}
} while ($x >= $end);
}
?>
</table>
</body>
answered Nov 16 '18 at 7:08
Trung NguyênTrung Nguyên
568
568
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331727%2fdo-while-loop-not-looping-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What values are you entering and what is its output?
– Kamal Paliwal
Nov 16 '18 at 5:07