Hiya,
Straight to the question. I have a client who is looking for something along the lines of this: The Source (The calculator bit)
But I don't have a clue how to even start to go about building it. I have basic knowledge of PHP and good knowledge of javascript, css etc . . . but have never really delved into the realms of databases.
Can anyone give me any pointers, tutorials, etc . . . on how to build something like this.
Thanks
Not if you know what you're doing... How much Javascript do you know? Are you comfortable with the XMLHttpRequest Object and XML? How good are you with databases? Do you know how to normalise a database?
Then it's probably best to get somebody else to do it.
Yeah that does sound like a better option. What about something like this: Easier Calc.
Surely it would be easier as long as I know the equation to implement and not run off a database?
Well if you know the equation and you aren't bothered about dynamically getting the car models' MPG then yeah it's just simple Javascript.
I'll use your second site example since it's a bit more straight forward than the first (although they're essentially doing the same thing) and doesn't require a database.
Here's what'll be happening: Someone fills in some numbers, they submit those values, PHP takes those values and inserts them into an equation, and then throws back the results.
The input fields will be handled via HTML. The passing and inserting those values into the equation(s) will be handled via PHP.
You can do this all from 1 PHP file, let's call it myCalc.php
If you want a slightly more advanced explanation of how your other example works, just let me know. Hope that helps!PHP Code:<?php
$isSubmitted = $_REQUEST['isSubmitted']; //these names HAVE to match the input field "name" attribute
$varA = $_REQUEST['field1'];
$varB = $_REQUEST['field2'];
$varC = $_REQUEST['field3'];
if ($isSubmitted == "true" && $varA != "" && $varB != "" && $varC != "") { //if the form was submitted and all fields were filled out, run the equation and show results...
$theResult = ($varA + $varB) / $varC; //whatever the equation is
$showResults = "true";
} else if ($isSubmitted == "true" && ($varA == "" || $varB == "" || $varC == "")) { //..otherwise throw an error
$showResults = "false";
};
?>
<html>
<head></head>
<body>
<form action="myCalc.php" method="post" enctype="multipart/form-data">
<!-- when the form is submitted, it will send it to itself (basically refreshing the page, but with the form values) -->
<input type="text" name="field1" value="<?php echo $varA; ?>" />
<!-- making the "value" attribute equal to the PHP variable will keep the entered values intact
(in other words not clearing them when the form is submitted) -->
<input type="text" name="field2" value="<?php echo $varB; ?>" />
<input type="text" name="field3" value="<?php echo $varC; ?>" />
<input type="submit" value="Submit" />
<input type="hidden" name="isSubmitted" value="true" />
</form>
<?php
//check for results and errors
if ($showResults == "true") {
echo 'The result is '.$theResult;
} else if ($showResults == "false") {
echo '<font color="red">Please fill in all required fields</font>';
};
?>
</body>
</html>![]()
Last edited by SineQuaNon; 25-06-2009 at 10:55 PM. Reason: Apparently the page parses <br /> tags even if they're wrapped in [PHP][/PHP] tags...
Check the forum often for the latest design announcements. Everything from graphic design and web design, to films and music. Estetica is a great place for people to get together and help each other out.
Bookmarks