Jump to content
Larry Ullman's Book Forums

short.fuse.5254

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by short.fuse.5254

  1. I'm having issues with Page 214 -Chapter 7-... 

     

    This is how the book showed the example turning out: 

     

    AVGbalance.png

     

    This is how mine turned out:

     

    842014_1.png

     

    This example on page 215 is not working right either: 

     

    image.pngI don't understand where I went wrong & why the examples aren't turning out like the author's on these. I downloaded the sql commands that go with the book & ran this on the sql tab in PhpMyAdmin:

    CREATE DATABASE banking CHARACTER SET utf8 COLLATE utf8_general_ci;
    USE banking;
    
    CREATE TABLE customers (
    customer_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    first_name VARCHAR(20) NOT NULL,
    last_name VARCHAR(40) NOT NULL,
    PRIMARY KEY (customer_id),
    INDEX full_name (last_name, first_name)
    ) ENGINE = INNODB;
    
    CREATE TABLE accounts (
    account_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    customer_id INT UNSIGNED NOT NULL,
    type ENUM('Checking', 'Savings') NOT NULL,
    balance DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT 0.0,
    PRIMARY KEY (account_id),
    INDEX (customer_id),
    FOREIGN KEY (customer_id) REFERENCES customers (customer_id) ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE = INNODB;
    
    CREATE TABLE transactions (
    transaction_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    to_account_id INT UNSIGNED NOT NULL,
    from_account_id INT UNSIGNED NOT NULL,
    amount DECIMAL(5,2) UNSIGNED NOT NULL,
    date_entered TIMESTAMP NOT NULL,
    PRIMARY KEY (transaction_id),
    INDEX (to_account_id),
    INDEX (from_account_id),
    INDEX (date_entered),
    FOREIGN KEY (to_account_id) REFERENCES accounts (account_id)
    ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY (from_account_id) REFERENCES accounts (account_id) 
    ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE = INNODB;
    
    INSERT INTO customers (first_name, last_name) 
    VALUES ('Sarah', 'Vowell'), ('David', 'Sedaris'), ('Kojo', 'Nnamdi');
    INSERT INTO accounts (customer_id, balance) 
    VALUES (1, 5460.23), (2, 909325.24), (3, 892.00);
    INSERT INTO accounts (customer_id, type, balance) 
    VALUES (2, 'Savings', 13546.97);
    
    
  2. I think I've got this all sorted out now, so I figured I should post how I got everything done to help anyone else who has the same problem. 

     

    First, I clicked the xampp control panel, & clicked the stop buttons next to Apache & MySQL.

     

    Next, I went to: http://downloads.mysql.com/general/timezone_2011n_posix.zip ,

    & I downloaded the zip folder (It has all of the 15 tables files in it.).

     

    I extracted the folder, selected all of the 15 files in it, copied them,

    & pasted them in the folder C:\xampp\mysql\data\mysql.

     

    A window will come up asking you if you want to replace the files or skip them:

     

    Replace them...

     

    Then I restarted Apache & MySQL & got the example in Chapter 6 on page 194 to work!

     

    194_8_Mine.png

  3. Hi everyone,

     

    I just finished reading Chapter 6, & I'm stuck on Page 190 on the part Using Time Zones in MySQL...

    I'm not sure where to start.

    I checked out this page http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html,

    but I can't make too much sense out of it!

    I installed Xampp in C:.

    I found this folder with the Time Zone tables, but I have no idea what to do even after reading the time zone support page on the MySQL website...:

     

    C:\xampp\mysql\data\mysql

     

    It has all 15 of the time zone files, but I don't know what to do.

     

    I'm using Version 3.2.1 of Xampp, Version 5.5.11 of PHP, & Version 5.0.11 -dev of MySQL...

     

    I tried example 8 on Page 194 of the book, & this is how it turned out:

     

    194_8.png

    I appreciate in help in advance! 

     

    Thanks,

    -- Devin

  4. Hello,

     

    I think you can leave them as they are for now. If there are exercises where you need the registration date, you can change the registration date for some of them then, or add users so as to have a diversity of registration dates.

     

    Emilie

    Thank you Emilie! I appreciate all of the help! & I also voted your answer up for answering what I needed to know & the quick reply...  :)

  5. Hello,

     

    What is "wrong", according to you?

     

    The registration date is the same for all users because you entered all of them at one go into the database, and therefore the timestamp corresponding to NOW() is the same for everyone. Because of that, ordering the results by registration_date DESC has no real meaning.

     

    I hope this helps,

     

    Emilie

    Hi Emilie,

     

    I was just judging by the examples in the book & thought what I did was supposed to match the examples exactly.

    I was thinking that if the registration_date wasn't the same as the author's in the book, then I might run into problems later on in the book... So, do I need to edit the registration_date in phpMyAdmin to make the registration dates the same as the authors? I just thought I might run into issues if the registration dates didn't match the authors exactly. &, by the way, thanks for the quick reply & for explaining this!

  6. Hello everyone,

     

    This is what I'm having trouble with in Chapter 5 on the part 'Sorting Query Results' on page 146:

     

    Show all of the non-Simpson users by
    date registered C:
    SELECT * FROM users
    WHERE last_name != 'Simpson'
    ORDER BY registration_date DESC;
    

    This is how it turned out when I followed the example:

     

    image.png

     

    I don't understand why it's not turning out like the example in the book

    & why the registration date turned out like this!

     

    I followed the authors examples & downloaded the scripts that go along with the book.

     

    I copied & pasted this -from the books scripts phpmysql4_scripts\sql.sql-

    into the SQL form on phpMyAdmin:

    CREATE DATABASE sitename;
    
    USE sitename;
    
    CREATE TABLE users (
    user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
    first_name VARCHAR(20) NOT NULL,
    last_name VARCHAR(40) NOT NULL,
    email VARCHAR(60) NOT NULL,
    pass CHAR(40) NOT NULL,
    registration_date DATETIME NOT NULL,
    PRIMARY KEY (user_id)
    );
    
    INSERT INTO users 
    (first_name, last_name, email, pass, registration_date) 
    VALUES ('Larry', 'Ullman', 'email@example.com', SHA1('mypass'), NOW());
    
    INSERT INTO users VALUES 
    (NULL, 'Zoe', 'Isabella', 'email2@example.com', SHA1('mojito'), NOW());
    
    INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES
    ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
    ('George', 'Harrison', 'george@beatles.com ', SHA1('something'), NOW()),
    ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
    
    INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES
    ('David', 'Jones', 'davey@monkees.com', SHA1('fasfd'), NOW()),
    ('Peter', 'Tork', 'peter@monkees.com', SHA1('warw'), NOW()),
    ('Micky', 'Dolenz', 'micky@monkees.com ', SHA1('afsa'), NOW()),
    ('Mike', 'Nesmith', 'mike@monkees.com', SHA1('abdfadf'), NOW()),
    ('David', 'Sedaris', 'david@authors.com', SHA1('adfwrq'), NOW()),
    ('Nick', 'Hornby', 'nick@authors.com', SHA1('jk78'), NOW()),
    ('Melissa', 'Bank', 'melissa@authors.com', SHA1('jhk,h'), NOW()),
    ('Toni', 'Morrison', 'toni@authors.com', SHA1('hdhd'), NOW()),
    ('Jonathan', 'Franzen', 'jonathan@authors.com', SHA1('64654'), NOW()),
    ('Don', 'DeLillo', 'don@authors.com', SHA1('asf8'), NOW()),
    ('Graham', 'Greene', 'graham@authors.com', SHA1('5684eq'), NOW()),
    ('Michael', 'Chabon', 'michael@authors.com', SHA1('srw6'), NOW()),
    ('Richard', 'Brautigan', 'richard@authors.com', SHA1('zfs654'), NOW()),
    ('Russell', 'Banks', 'russell@authors.com', SHA1('wwr321'), NOW()),
    ('Homer', 'Simpson', 'homer@simpson.com', SHA1('5srw651'), NOW()),
    ('Marge', 'Simpson', 'marge@simpson.com', SHA1('ljsa'), NOW()),
    ('Bart', 'Simpson', 'bart@simpson.com', SHA1('pwqojz'), NOW()),
    ('Lisa', 'Simpson', 'lisa@simpson.com', SHA1('uh6'), NOW()),
    ('Maggie', 'Simpson', 'maggie@simpson.com', SHA1('plda664'), NOW()),
    ('Abe', 'Simpson', 'abe@simpson.com', SHA1('qopkrokr65'), NOW());
    

    I don't understand why this is turning out wrong!

     

    I got the example -on page 145- to work:

     

    To sort data:
     
    1. Select all of the users in alphabetical
    order by last name A:
     
    SELECT first_name, last_name FROM
    users ORDER BY last_name;
    

    This is what mine turned out like A:

     

    145_A_Mine.png

     

    I also got the second example on page 145 to work:

     

    2. Display all of the users in alphabetical
    order by last name and then first name B:
     
    SELECT first_name, last_name FROM
    users ORDER BY last_name ASC,
    first_name ASC;
    

    This is how mine turned out B:

     

    145_B_Mine.png

     

    I don't understand. I'm confused. I tried both of the examples on page 145 & I got them to work.

    But the example on page 146 DOES NOT...

     

     

    Thanks in advance for any help, ---It will be much appreciated---

     

    -- Devin

  7. This is the script that I'm having trouble with: 

    <?php # Script 3.6 - calc3_2.php 
    
    // This sets the page's title:
    $page_title = 'Trip Cost Calculator';
    
    // This includes the header:
    include ('includes/header.html');
    
    // Check for form submission:
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    	// Minimal form validation... Checks if distance, gallon_price, & efficiency are set & numeric...
    	
    	if (isset($_POST['distance'], $_POST['gallon_price'], $_POST['efficiency']) && is_numeric($_POST['distance']) && is_numeric($_POST['gallon_price']) && is_numeric($_POST['efficiency']) ) {
    	
    	// Calculate the results:
    	$gallons = $_POST['distance'] / $_POST['efficiency']; // This divides the distance the user enters by the efficiency the users enters & assigns it to the variable $gallons...
    	$dollars = $gallons * $_POST['gallon_price']; // This multiplies the gallons by the gallon price the user selected & assigns it to $dollars...
    	$hours = $_POST['distance']/65; // This divides the distance the user enters by 65... 
    	
    	// Print the results:
    	echo '<h1>Total Estimated Cost</h1>
    	<p>The total cost of driving ' . $_POST['distance'] . ' miles, averaging ' . $_POST['efficiency'] . ' miles per gallon, and paying an average of $' . $_POST['gallon_price'] . ' per gallon, is $' . number_format ($dollars, 2) . '. If you drive at an average of 65 miles per hour, the trip will take approximately ' . number_format($hours, 2) . ' hours.</p>';
    	
    } else { // If the user did something wrong
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
    	}
    
    } // End of main submission IF.
    
    // Leave the PHP section & create the HTML form:
    
    ?>
    
    <h1>Trip Cost Calculator</h1>
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
    	<p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>" /></p>
    	<p>Ave. Price Per Gallon: <span class="input">
    		 
    		<input type="radio" name="gallon_price" value="3.00" <?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '3.00')) echo 'checked="checked" '; ?>/> 3.00 
    		
    		<input type="radio" name="gallon_price" value="3.50"
    		<?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '3.50')) echo 'checked="checked" '; ?>/> 3.50
    		
    		<input type="radio" name="gallon_price" value="4.00" <?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '4.00')) echo 'checked="checked" '; ?>/> 4.00
    	</span><p>
    	<p>Fuel Efficiency: <select name="efficiency">
    		
    		<option value="10" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option>
    		
    		<option value="20" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option>
    		
    		<option value="30" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '30')) echo ' selected="selected"'; ?>>Very Good</option>
    		
    		<option value="50" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '50')) echo ' selected="selected"'; ?>>Outstanding</option>
    		
    	</select></p>
    	
    	<p><input type="submit" name="submit" value="Calculate!" /></p>
    	
    </form>
    
    <?php include ('includes/footer.html'); ?>
    

    I understand everything until this part: 

    
    <h1>Trip Cost Calculator</h1>
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
    	<p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>" /></p>
    	<p>Ave. Price Per Gallon: <span class="input">
    		 
    		<input type="radio" name="gallon_price" value="3.00" <?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '3.00')) echo 'checked="checked" '; ?>/> 3.00 
    		
    		<input type="radio" name="gallon_price" value="3.50"
    		<?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '3.50')) echo 'checked="checked" '; ?>/> 3.50
    		
    		<input type="radio" name="gallon_price" value="4.00" <?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '4.00')) echo 'checked="checked" '; ?>/> 4.00
    	</span><p>
    	<p>Fuel Efficiency: <select name="efficiency">
    		
    		<option value="10" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option>
    		
    		<option value="20" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option>
    		
    		<option value="30" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '30')) echo ' selected="selected"'; ?>>Very Good</option>
    		
    		<option value="50" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '50')) echo ' selected="selected"'; ?>>Outstanding</option>
    		
    	</select></p>
    	
    	<p><input type="submit" name="submit" value="Calculate!" /></p>
    	
    </form>
    // I know the part below includes the footer
    <?php include ('includes/footer.html'); ?>
    

    I would very much appreciate it if you could break the script down for me & explain it for me. The parts like this are really confusing me - I don't understand what they do for the rest of the script: 

    <option value="30" <?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '30')) echo ' selected="selected"'; ?>>Very Good</option>
    	
    	
    ?php if (isset($_POST['gallon_price']) && ($_POST['gallon_price'] == '3.50')) echo 'checked="checked" '; ?>/> 3.50
    
×
×
  • Create New...