Jump to content
Larry Ullman's Book Forums

David John

  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

642 profile views

David John's Achievements


Newbie (1/14)



  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?
  • Create New...