Welcome to WebmasterWorld Guest from 54.80.97.221

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

if and statement

code

     
5:46 pm on Aug 15, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Hi guys i want to be able to input a height size and a width size an depending on the input show a list of components needed. This is to generate a cutting list for kitchen units to be manufactured. I want to put it on a webpage and display the results. Any help greatly appreciated.

For example if height = 2200 and width = 1000 then 2 x sides 2200 x 570, 1 x top 964 x 570, 1 base 964 x 570.

The height stays same but the width deducts 36 from the amount.

Thanks
8:24 pm on Aug 15, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14718
votes: 614


Let's double-check before continuing: You want to do this in php? It seems more like a javascript question. (Sure, the code will be almost identical, but let's post in the right place.)
5:49 am on Aug 16, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Hi Lucy, thank you for your reply. Which ever is the best to use php or javascript. I have tried a few things but not working. I want to be able to go on the page type in the 2 inputs hit a button and the results show either in the page or an i frame. I'm afraid i'm not that technical with this kind of coding but it would help my business immensely and stop me repeatedly having to write these out individually. I tried to get help on a if and statement but as there would be lots of coding to do with different sizes i didn't get any help. So i thought if i could have 2 inputs one for width and one for height and the code works it out i could do most of the coding myself i just need to basic function. Also how do i put this code on my webpage. I am very grateful for any advice and help with this issue.
Many thanks for your time.
5:51 am on Aug 16, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:11532
votes: 702


You want to do this in php? It seems more like a javascript question
PHP may be a better choice nowadays. JS is counted as one more file to load.
6:04 am on Aug 16, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


php it is then any help appreciated.
12:16 pm on Aug 16, 2017 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 308
votes: 21


For example if height = 2200 and width = 1000 then 2 x sides 2200 x 570, 1 x top 964 x 570, 1 base 964 x 570.


Where does this "data" come from, or is it literally just a one-off standalone calculation?

When you say, "2 x side 2200 x 570" - presumably that 2200 is now a "width" dimension, that matches the "height" initially specified?

Also, when you say "width deducts 36 from the amount", are you referring to the 1000 - 36 = 964? Which applies only to the "top" and "base", but not the "sides"?

... lots of coding to do with different sizes


So, there are lots of different sizes, that warrant "lots of coding"? Exactly what "data" this is and how it is stored could well be the core to how you write this, otherwise, it's just a one-off IF statement (as the thread title suggests)? (Or lots of hardcoded IF statements, which should be avoided.)

Actually, where is the "IF statement" here... Isn't it just a series of calculations based on the width and height, or is there something specific about this width and height that requires just these specific calculations?
4:37 pm on Aug 16, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14718
votes: 614


I want to be able to go on the page type in the 2 inputs hit a button and the results show either in the page or an i frame.

When you say "I" do you mean the user of the site? Do the height and width dimensions then refer to the user's actual kitchen (or lab or whatever it is), so the values can be absolutely any number?

In addition to the number-crunching--which is trivial, since it's just a matter of doing suchandsuch with $height and othersuchandsuch with $width--you'll want a little bit of input filtering, such as constraining the number of permitted decimal places, and presumably setting an overall range on permitted values. That applies especially to the $height value: if your kitchen has a 15-foot cathedral ceiling, you're not going to have floor-to-ceiling cabinets. That's why I started out thinking it seems like a javascript process. In fact it's such a small script, it can easily be incorporated into the page itself--assuming the function is only invoked on one page--so no need for additional downloads.

By the usual yawn-provoking coincidence, it's only a few days since someone was asking about values containing . or , and how to make sure they got processed appropriately.

Are you starting to get the impression that people are actively trying to avoid answering your original question? ;)
8:11 pm on Aug 16, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts:131
votes: 2


Are you looking for something in the order of: a size is selected or inputted and the results are a listing of what you need to manufacture something according to the size entered?


Be short & sweet & and to the point---you have to many numbers flying around
8:26 pm on Aug 16, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts:131
votes: 2


btw, is 570 a constant figure?
8:46 pm on Aug 16, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts:131
votes: 2


Putting it in a nutshell:
Okay, you’ll need two inputs, one for height and one for width.
<input type=”text”name=”height”><br>
<input type=”text”name=”width”><br>
<input type=”submit”>

Next, in your processing script, first, you are going to make sure only numbers have been input.
Then, assuming you are using height and width as your variable names:
$adjusted_width=$width – 64;
$height=”$height”;
Echo” <p>Sides (2) $height x 570&#59,<br>
Top (1) $adjusted_width x 570<br>
Base (1) $adjusted_width x 570 </p>”;
11:55 pm on Aug 16, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14718
votes: 614


<tangent>
Funny, I was just saying in another thread that I generally have to leave Smart Quotes disabled. Here’s why.
</tangent>

:: detour to confirm that 59 = 3b = ; (semicolon) ::

Is something missing?
12:34 am on Aug 17, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


$adjusted_width=$width – 64;
$height=”$height”;
Echo” <p>Sides (2) $height x 570<br>
Top (1) $adjusted_width x 570<br>
Base (1) $adjusted_width x 570 </p>”;
1:07 am on Aug 17, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


Actually I promoted redundancy if the top and base are both the same size, of course, I guess the application calls for a separation.
6:07 am on Aug 17, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Thats looking good typo how do i put the code into my webpage i know i may sound stupid. Thank you everyone for your patience.
11:56 am on Aug 17, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Thank you typomaniac ur advice has been very helpfull.
6:21 pm on Aug 17, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


this is the code i used for input page :

<html>
<body>

<form action="process.php" method="post">
Height: <input type="text" name="height"><br>
Width: <input type="text" name="width"><br>
<input type="submit">
</form>

</body>
</html>

this is the process script :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Estimator</title>
<meta name="generator" content="generator">
<style>
div#container
{
width: 994px;
position: relative;
margin: 0 auto 0 auto;
text-align: left;
}
body
{
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-weight: normal;
font-size: 13px;
line-height: 1.1875;
margin: 0;
text-align: center;
}
a
{
color: #0000FF;
text-decoration: underline;
}
a:hover
{
color: #FF0000;
text-decoration: underline;
}
</style>
</head>
<body>

<?php
$adjusted_width=$width – 64;
$height=”$height”;
Echo” <p>Sides (2) $height x 570<br>
Top (1) $adjusted_width x 570<br>
Base (1) $adjusted_width x 570 </p>”;
?>
<div id="container">
</div>
</body>
</html>

i cant get the process.php page to work ?



[edited by: not2easy at 8:01 pm (utc) on Aug 17, 2017]
[edit reason] anonymized autogen content [/edit]

8:43 pm on Aug 17, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14718
votes: 614


Let's backtrack at this point.

What is your previous experience with javascript?
What is your previous experience with php?

The question is: what things do you already know how to do?
5:57 am on Aug 18, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Hi Lucy,

I have limited experience hence the need for help. I have a small company that makes units hence the idea of this page to create a cutting list. I do my web pages on a wusiwug editor so everything coded for me. I was going to try and use a simple drop down menu linked to a page in an iframe to display all the possible standard sizes but it will take a long time to do. It would be easier just for me to input the two sizes the height and width and then display the results to generate a cutting list. I need the width though to be minus 64 taking of the thickness of the two sides. For example if i type in 720 high and 500 wide i want the results to show the following :

2 sides 720 x 560
1 base 560 x 464 (which is the width -64)
1 top 150 x 464 (which is the width -64)
1 shelf 440 x 464 (which is the width - 64)
1 back 702 x 464 (which is the width - 64)

the height will always stay the same but the width is - 64 so i can input various sizes rather than have to write out every size possible.
i am not that good with coding i know it must be easy for an expert to write i am old fashion in my ways but something like this would be so time saving for me to do.The idea that typomaniac above wrote looks good in code but i cant get it to work. I am sorry if i come across as totally stupid but thats why i am asking for help.
6:22 am on Aug 18, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 29, 2005
posts:8174
votes: 611


You're asking for a turn key solution. We don't always do that, but we also recognize that you need some real help so.... As lucy24 asked, how much js or php do you know?

Can you write a simple php to say "hello world" ?

If not, learn to do that then learn how to script

2 + 2 = 4 as two input values on a form and direct the result to an output html. If you can do that, you can code the script that you want.
6:59 pm on Aug 18, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


First things first, what kind of server host do you have and do you have permission to run .PHP, .JavaScript ? If you have that you’ll be good to go. I’m not sure what kind of math you’re doing, but
500 – 64 != 464
Your original number was x570 and now it is x560
The 36 has turned into a 64.
You need to get your constants down as well as your deduction number.
8:34 pm on Aug 18, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Hi i am sorry my brain is mashed with figures i want the width to show -36 so a value of 500 would return 464. I can run php on my server but cant get this idea to work.
9:04 pm on Aug 18, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


I'll get you up and going but it won't be a pronto thing as I'm busy chasing down info for my own project from half a world away. As soon as I get a minute I'll write it up 4 U.
9:14 pm on Aug 18, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Thank you i really appreciate your help i am very grateful for this.
10:02 pm on Aug 18, 2017 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 308
votes: 21


Just taking a step backwards for a mo... this sounds like an internal business tool to calculate a bunch of numbers from a couple of inputs. Something to make your life easier; to get the job done; the sooner the better. There only seems to be one calculation (deducting 36 from the input). I've got to ask... is there any reason why you're not just using a spreadsheet?

Creating an interactive web page seems a little excessive for the task described. Unless, of course, the real exercise is building an interactive web page? (Or there are other criteria we are not aware of?)
4:13 am on Aug 19, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


Here is what you're looking for, I hope. Its pretty bare bones and I didn't stick with your css coding but you can change things to taste. I used an <h1> tag for the numbers because they were pretty small but the variables are re-usable as long as they're withing the <?php and ?> tags(stick with the ones where the content is. I would make a copy for reference so you can always go back to just in case. Make sure the page you put this page on has a .php extension, that is pagename.php (substitute page name with what ever you decide to name it. Let me know how it works out for you.

<!DOCTYPE HTML> 
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>

<?php
// define variables and set to empty values
$heightErr = $widthErr = "";
$height = $width=$deduct="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {

if (empty($_POST["height"])) {
$heightErr = "Height is required and must be numerical";
} else {
$height = test_input($_POST["height"]);
}
if (empty($_POST["width"])) {
$widthErr = "Width is required and must be numerical";
} else {
$width = test_input($_POST["width"]);
}
if (empty($_POST["deduct"])) {
$deduct = "";
} else {
$deduct = test_input($_POST["deduct"]);
}
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;

}
?>

<h2>Estimator</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Height: <input type="number" name="height"required><span class="error">* <?php echo $heightErr;?></span>
<br><br>
Width: <input type="number" name="width"required><span class="error">* <?php echo $widthErr;?></span>
<input type="hidden"name="deduct"value="36">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>

<?php

echo"<h1>Height: ";
echo $height;
echo"<br><br>Width: ";
$adj_width=$width-$deduct;
echo $adj_width;
echo"</h1>";
?>

</body>
</html>
5:18 am on Aug 19, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14718
votes: 614


<tangent>
What happens to the other 36mm? Is your construction material exactly 18mm thick?

This question became less vexatious after I whapped myself upside the head and realized that it's not 36cm, leading to the corollary understanding that input values will always be integers.
</tangent>
5:41 am on Aug 19, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


I will try this thank you. Lucy yes the material sides are 18 thick each.
8:43 am on Aug 20, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Thank you for the formula to deduct the thickness of the units. I have tweaked the coding a little. When i re load the page it still shows the figures from previous. How do i make sure when page is first loaded no values are shown until numbers inputted and submitted and how do i display the results in an i frame instead of same page ?

Here is the code i am using thanks to typomainiac

<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>

<?php
// define variables and set to empty values
$heightErr = $widthErr = "";
$height = $width=$deduct="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {

if (empty($_POST["height"])) {
$heightErr = "Height is required and must be numerical";
} else {
$height = test_input($_POST["height"]);
}
if (empty($_POST["width"])) {
$widthErr = "Width is required and must be numerical";
} else {
$width = test_input($_POST["width"]);
}
if (empty($_POST["deduct"])) {
$deduct = "";
} else {
$deduct = test_input($_POST["deduct"]);
}
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;

}
?>

<h2>Estimator</h2>
<p><span class="error"></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Height: <input type="text" name="height"><span class="error"><?php echo $heightErr;?></span>
<br><br>
Width: <input type="text" name="width"><span class="error"><?php echo $widthErr;?></span>
<input type="hidden"name="deduct"value="36">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>

<?php

echo"<h1> Height = 2 sides $height mm x 560 mm <br>";
echo"<br>Width = 1 base 510 mm x ";
$adj_width=$width-$deduct;
echo $adj_width;
echo"<br>Width = 1 top 150 mm x ";
$adj_width=$width-$deduct;
echo $adj_width;
echo"<br>Width = 1 shelf 440 mm x ";
$adj_width=$width-$deduct;
echo $adj_width;
echo"<br>Width = 1 back 702 mm x ";
$adj_width=$width-$deduct;
echo $adj_width;
?>

</body>
</html>
1:21 pm on Aug 21, 2017 (gmt 0)

Junior Member from US 

5+ Year Member

joined:Feb 11, 2010
posts: 131
votes: 2


You could put your form on one page and your processor on another one. Not sure but I'm thinking the 0 displayed before anything is entered is the value displayed before any are entered. You could probably get rid of that with css. I've never used Iframes but there's lots of information to be found by googling the word.

You should also look into learning basic html and css followed by css coding. You can usually find decent information at a local library, and online all you have to do is google your situation and you can pretty much count on finding solutions but you should at least try to get a handle on what's going on. [html.net ] looks like it could be a pretty good site though I've never there yet.
2:28 pm on Aug 21, 2017 (gmt 0)

New User

joined:Aug 15, 2017
posts: 11
votes: 0


Thanks typomaniac for all your help i really appreciate this ive sorted it now working like a dream. Thanks so much.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members