Jump to content
Larry Ullman's Book Forums

David John

Members
  • Content Count

    41
  • Joined

  • Last visited

Everything posted by David John

  1. Give this a try (I am certainly no accountant, so please double-check to make sure this is how pay is deducted). And I intentionally left off overtime pay (unaware of the rate) as well as first name, last name, and net pay, but you probably get the idea. paycheck.html: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>PayCheck</title> <!--[if lt IE 9]> <script src="http://html5shiv.goo...5.js"></script> <![endif]--> <script src="forum.js"></script> </head> <body> <!-- PayCheck.html --> <form action="" method="post" id="theForm"> <fieldset> <p>Use this form to calculate the Regular Pay. Overtime Pay. Gross Pay, and Net Pay for an employee.</p> <div> <label for="quantity">Regular Hours Worked</label> <input type="number" name="hours" id="hours" value="1" min="1" required> </div> <div> <label for="price">Hourly Rate</label> <input type="text" name="rate" id="rate" value="1.00" required> </div> <div> <label for="FICAtax">FICA Tax Rate (%)</label> <input type="text" name="FICAtax" id="FICAtax" value="0.0" required> </div> <div> <label for="statetax">State Tax (%)</label> <input type="text" name="statetax" id="statetax" value="0.00" required> </div> <div> <label for="fedtax">Federal Tax (%)</label> <input type="text" name="fedtax" id="fedtax" value="0.00" required> </div> <div> <label for="total">Total</label><input type="text" name="total" id="total" value="0.00"> </div> <div> <input type="submit" value="Calculate" id="submit"> </div> </fieldset> </form></body> </html> forum.js // Function called when the form is submitted. // Function performs the calculation and returns false. window.onload = init; function init() { 'use strict'; document.getElementById('theForm').onsubmit = calculate; } // End of init() function. function calculate() { 'use strict'; //create a variable to store the total var total; //create a variable to get the value of the hours var hours = document.getElementById('hours').value; //create a variable to get the value of rate var rate = document.getElementById('rate').value; //create a variable to get the value of FICA tax var FICAtax = document.getElementById('FICAtax').value; //create a variable to get the state tax var statetax = document.getElementById('statetax').value; //create a variable to get the federal tax var fedtax = document.getElementById('fedtax').value; //total is equal to hours * rate total = hours * rate; //i.e. if the tax rate is 8.25%, divide 8.25/100 to get .0825 FICAtax /= 100; statetax /= 100; fedtax /= 100; total = (hours*rate) - (hours*rate*FICAtax) - (hours*rate*statetax) - (hours*rate*fedtax); // Format the total: total = total.toFixed(2);//a number is object (of the type "Number") and has built-in methods like toFixed(), setting digits to the right of the decimal. //display this where id="total" in the HTML document.getElementById('total').value = total; //prevent the submission of the form return false; } // End of calculate() function.
  2. Hey all, I figured I would share one of my projects inspired by Larry's effortless e-commerce book(s): https://www.broadbandguitar.com/ We offer online music lessons from incredibly talented guitarists.
  3. Larry, I have been doing some google searches and did not find a sufficient answer. Will keep trying. The answer is out there!
  4. Love the book, Larry. It has been extremely helpful to me, and I have revamped my (soon-to-be) e-commerce site to accommodate the updates that you provided in the "First Site". But one thing eludes me, and that is how to get the navbar to collapse when viewed in portrait mode on an iPad (everything works well on the iPhone). I did not use LESS for the bootstrap files, so what line of code determines the point at which the navbar collapses? Any help would be appreciated.
  5. Great tips. Definitely will take these into account. Thanks, Larry!
  6. Happy New Year! Hopefully this is the correct place to put this question. For those of you who freelance or do contract work, what is the best way to determine how much to charge clients/customers? The initial time investment and research was very high, but now that I have completed my project, I can essentially "re-use" the code, making tweaks here and there. Any advice would be appreciated.
  7. It works now (thank God!) As usual, many thanks to HartleySan and Larry for your input. Next question: I am using "airportDesignator" (from the hotels table) in the "hotels_id" column (from the information table) when the comments are submitted. Does this violate 1NF/2NF/3NF or compromise referential integrity at all?
  8. Sorry for being unclear, HartleySan. Please correct me if I'm wrong, but doesn't INSERT INTO SELECT replace the use of VALUES? I could be mistaken, but I thought this was the case. To illustrate an example of my objective, say a user wants to comment on/rate a hotel in Albany whose id = 1 in the hotels table. The GET query grabs the hotel id, the user enters his/her comments, and submits. What's inserted into the information table is the value of Albany (1) into the "hotels_id" column as well as the user's comments in the "comments" column in the information table. In addition, I hope to eventually add "ratings" and "date created". I realize now that my SQL query was way off. Thanks for pointing that out! I keep getting a parse error with this: $sql = "INSERT INTO information (hotels_id, comments, ratings) VALUES (:id, :comments, :ratings) WHERE hotels.id=:id";
  9. Hi, everyone. There's a project I'm working on, and I would love to get a bit of help from developers who visit this forum. Here's the background: This is an app that will allow users to post comments/reviews about hotels that they stay in. I decided to make two tables: hotels and information (for the comments). hotels table: CREATE TABLE IF NOT EXISTS `hotels` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `airportDesignator` varchar(11) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `hotelName` varchar(255) NOT NULL, `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `city` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `state` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `zip` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_swedish_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=73 ; information table: CREATE TABLE IF NOT EXISTS `information` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `hotels_id` int(10) unsigned NOT NULL, `comments` blob, `ratings` int(10) DEFAULT NULL, `date_created` date NOT NULL, PRIMARY KEY (`id`), KEY `hotels_id` (`hotels_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ; To get the hotels, here's the query I used: $sql = "SELECT * FROM hotels WHERE hotels.id=:id"; To add the comments, I used this query: $sql = "INSERT INTO information (hotels_id, comments, ratings, date_created) (SELECT hotels_id, comments, ratings, date_created FROM information LEFT JOIN hotels ON hotels.id = information.hotels_id)"; The hotels_id is inserting a "0" instead of the id from the hotels table, and I would love to know how to get the correct id (from the hotels table) inserted into the information table. Does hotels_id need to be a foreign key in order for the INSERT statement to work properly, or do I need to change the SQL INSERT query? If anyone needs further clarity, please let me know. Any feedback would be greatly appreciated.
  10. Not sure why, Larry, but whenever I post in this forum, I end up solving my problem! I replaced "GROUP BY" with "ORDER BY" and now I think it works. Thanks for your books and resources; I truly have learned a lot from them.
  11. Certainly. Here's the INFO table: CREATE TABLE IF NOT EXISTS `info` ( `info_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `state_id` int(10) NOT NULL, `address` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `city` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `state` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `zip` varchar(30) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`info_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=938 ; And here's the STATES table: CREATE TABLE IF NOT EXISTS `States` ( `state_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `state_name` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `stateAbbr` varchar(6) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`state_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=53 ;
  12. Guys, I am trying to output ALL cities that match the following SQL query: SELECT info.state_id, info.address, info.city, info.state, info.zip FROM info INNER JOIN States ON info.state_id = States.state_id WHERE info.state_id=:id GROUP BY info.city And unfortunately, it returns only one result. Here's the try->catch I used: try { $dbh = new PDO("mysql:host=$host;dbname=$databasename", $user, $pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->prepare($sql); $stmt->bindParam("id", $_GET[id]); $stmt->execute(); $cities = $stmt->fetchAll(PDO::FETCH_OBJ); $dbh = null; echo '{"items":'. json_encode($cities) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } Now, I am almost certain that this is a problem with my query and not JSON. My question is, how do I alter the SQL so it will return EVERY city, not just one? Would greatly appreciate any input
  13. Larry, Thanks for the well-written tutorial on Stripe.js; I am still working on using it myself. In light of its popularity, do you think a section for Stripe implementation would be worthwhile?
  14. Very true! It's a medium-to-long-range plan (teaching). And to your point about "that's the way it should be done", I think that's when I will know that I truly grasp the concept. Looking forward to it!
  15. Teaching code is something I would like to do some day.
  16. Thanks for the link, HartleySan. And thanks for the tip, Larry. I've found that when I tinker with code, it only deepens my understanding.
  17. Thank you, Jaepee! Good photo with a great guitarist, too
  18. HartleySan and Larry, I think it works now! Will test some more to confirm, but so far it is returning I wanted. Here's how I did it: $q = 'SELECT * FROM pages LEFT JOIN users ON pages.user_id = users.id WHERE users.id = ' .$_SESSION['user_id']. ' AND category_id = ' .$_GET['id']. ' ORDER BY date_created DESC'; The second part of the SQL WHERE statement was included so that the content would be relevant to the category titles. I would like to thank you both again for your help. It seems I wasn't 100% clear in my question, so sorry about that...
  19. HartleySan and Larry, Thanks for the replies; I apologize if I caused any confusion. Let's say the admin logs in, wants to add a page/PDF for a particular member (we'll go with User X), selects the member in the dropdown menu, and then adds the content as desired. When X logs in, he will find his newly added content (which only he can see). I made user_id a foreign key in the "pages" table; then, as HartleySan had mentioned, added a user selector to add_page.php. With regard to a db structure change, is it correct to use an INNER JOIN on the "users" table (again, following the book's example)?
  20. In the book's first site, let's say you, the admin, wanted to add a page for a specific member only. That way, it is personalized for that user, and no one else, save the admin, can see those files. So in add_page.php, what is the correct way to go about it? Here's what I have so far. <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Fill out the form to add a page of content:</legend> <p><label for="first_name"><strong>Title</strong></label> <?php create_form_input('title', 'text', $add_page_errors);?></p> <p><label for="user"><strong>User</strong></label> <select name="user"<?php if (array_key_exists('user', $add_page_errors)) echo 'class="error"';?>> <option>Select One</option> <?php //retrieve all the categories and add to the pull-down menu $q = "SELECT id, username FROM users WHERE type='member' ORDER BY username ASC"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; //check for stickyness if (isset($_POST['user']) && ($_POST['user'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('user', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['user'] . '</span>'; ?></p> <p><label for="category"><strong>Category</strong></label> <select name="category"<?php if (array_key_exists('category', $add_page_errors)) echo 'class="error"';?>> <option>Select One</option> <?php //retrieve all the categories and add to the pull-down menu $q = "SELECT id, category FROM categories ORDER BY category ASC"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; //check for stickyness if (isset($_POST['category']) && ($_POST['category'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p> <p><label for="description"><strong>Description</strong></label><?php create_form_input('description', 'textarea', $add_page_errors); ?></p> <p><label for="content"><strong>Content</strong></label><?php create_form_input('content', 'textarea', $add_page_errors); ?></p> <p><input type="submit" name="submit_button" value="Add This Page" id="submit_button" class="formbutton"/></p> </fieldset> </form> Now, how can that user see his/her uploaded file after logging in? Is there a conditional statement (with the $_SESSION variable) that needs to go on page.php?
  21. No problem, HartleySan. Thanks for the kind words!
  22. My last project was an app using HTML5, CSS3, JQM, JSON, PHP/MySQL, and Phonegap. For Android: https://play.google.com/store/apps/details?id=com.motiveflowdesigns.latinmass&hl=en For iOS: https://itunes.apple.com/us/app/tlm-us/id535538977?mt=8
  23. Hi, Awesomo. HartleySan gave a fantastic answer; really couldn't have said it better myself. With regard to your follow-up question, I don't think you would need a js framework to use client-side form validation. There is a great example in Larry's current js book (chapter 10, to be precise) about forms; it uses regular expressions and js.
×
×
  • Create New...