+ Reply to Thread
Results 1 to 9 of 9

Thread: Database Driven Form/Calculator

  1. #1
    Mac Fanatic Jjpeacha's Avatar
    Join Date
    Nov 2008
    Location
    Norwich, UK
    Posts
    59

    Database Driven Form/Calculator

    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


  2. #2
    likes chips. Scriptage's Avatar
    Join Date
    May 2008
    Location
    Yorkshire
    Posts
    2,760

  3. #3
    Mac Fanatic Jjpeacha's Avatar
    Join Date
    Nov 2008
    Location
    Norwich, UK
    Posts
    59
    Excellent, thanks.

    I'm just wondering but is that type of calculator hard to create?

  4. #4
    likes chips. Scriptage's Avatar
    Join Date
    May 2008
    Location
    Yorkshire
    Posts
    2,760
    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?

  5. #5
    Mac Fanatic Jjpeacha's Avatar
    Join Date
    Nov 2008
    Location
    Norwich, UK
    Posts
    59
    Quote Originally Posted by Scriptage View Post
    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?
    Javascript, i'd say I'm okay at, the other two - not a clue.

  6. #6
    likes chips. Scriptage's Avatar
    Join Date
    May 2008
    Location
    Yorkshire
    Posts
    2,760
    Then it's probably best to get somebody else to do it.

  7. #7
    Mac Fanatic Jjpeacha's Avatar
    Join Date
    Nov 2008
    Location
    Norwich, UK
    Posts
    59
    Quote Originally Posted by Scriptage View Post
    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?

  8. #8
    likes chips. Scriptage's Avatar
    Join Date
    May 2008
    Location
    Yorkshire
    Posts
    2,760
    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.

  9. #9
    2fer SineQuaNon's Avatar
    Join Date
    Jun 2009
    Location
    Los Angeles, CA
    Posts
    242
    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

    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>
    If you want a slightly more advanced explanation of how your other example works, just let me know. Hope that helps!
    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...

+ Reply to Thread

Similar Threads

  1. Google Calculator Fail
    By kip in forum Search Engines
    Replies: 2
    Last Post: 29-09-2008, 01:30 PM
  2. Replies: 8
    Last Post: 07-09-2008, 06:17 PM
  3. Em based layouts - Vertical rhythm calculator
    By lolly in forum General Web Design Forum
    Replies: 2
    Last Post: 29-06-2008, 02:16 PM
  4. Free - FreelanceSwitch Hourly Rate Calculator
    By Toon in forum Graphic Design Business Forum
    Replies: 9
    Last Post: 22-08-2007, 06:47 PM
  5. Grid Calculator
    By Toon in forum General Web Design Forum
    Replies: 0
    Last Post: 07-05-2007, 12:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


The Graphics Forum Web Design Stuff Free Decent Downloads Free Quality Wallpapers Graphics Forum Free Vista Themes
The Top The Best Images Tech Talk 247 Logo Design - $149 Affordable Stock Vector Illustrations Creativecurio - Design Blog Graphic Design Advertising

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.



Web Hosting - UK Web Hosting services for business or personal website hosting needs.

Dedicated Servers - A full range of Managed Dedicated Server solutions suitable for all your requirements.

Graphic Design Blog | Web Design Forum | Graphic Design and Print Forum | Graphic Design Links | Advertise On This Site

Web Design UK | Vision.To Design | Leaflet Printing | Estetica Design Forum's Privacy Policy

Flyer Printing | Photography Blog | Design Forum Links | Logo Design | Graphic Design Social Network | Logo Design

Graphic Design Tutorials | Logo Designer | UK Logo Design Studio | Land for sale | Vector Art Blog | Leaflet Printing

Free Web Hosting | Custom Logo Design - $149 Only | Affordable Print Design Templates | Small Business Logo Design | Company Logo Design

Logo Design Service | Logo Design Firm | Logo Design Reseller | Custom Logo Design | Letterhead Printing | Flyer Printing | Business Card Printing

Printing | Leaflet Printing | Online Backup | T-Shirt Printing | Personalised Mugs | Canvas Printing | Free Web Hosting Comparison Site