Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Libby

  • Rank
  1. Hi Guys, I'm having some difficulty with the SQL to populate the messages table in Chapter 6, page 192. The SQL is included below, together with a screenshot of the resulting table. There are two questions relating to the records where the subject is "Database Design" 1) - message_id 2 by user 2 asking for help "I'm creating a new database..." - message_id 3 is a reply to the question "The number of tables in your database..." and has the parent_id 2 to indicate that. However, should the user_id here be 3, otherwise the original poster appears to be answering themselves? 2) The "Okay thanks" message is a reply to the reply, so should that have a parent_id of 3, or should it be linked to the overall parent message, message_id 2? The parent_id value 0 in the book doesn't seem right as this would suggest a new message (?) Many thanks Libby SELECT * FROM forums; SELECT user_id, username FROM users; INSERT INTO messages (parent_id, forum_id, user_id, subject, body, date_entered) VALUES (0, 1, 1, 'Question about normalization.', 'I''m confused about normalization. For the second normal form (2NF), I read...', UTC_TIMESTAMP()), (0, 1, 2, 'Database Design', 'I''m creating a new database and am having problems with the structure. How many tables should I have?...', UTC_TIMESTAMP()), (2, 1, 2, 'Database Design', 'The number of tables your database includes...', UTC_TIMESTAMP()), (0, 1, 3, 'Database Design', 'Okay, thanks!', UTC_TIMESTAMP()), (0, 2, 3, 'PHP Errors', 'I''m using the scripts from Chapter 3 and I can''t get the first calculator example to work. When I submit the form...', UTC_TIMESTAMP());
  2. On page 92, Chapter 3, making sticky forms: In this chapter a form is created with PHP used to create a text field for inputting distance. Code then validates the content to make sure it is present and a number. The form remembers what was entered so that if an error is thrown the previous input is still there. The following code is used to remember the distance entered by the user. <?php if (isset($_POST['distance'])) { echo $_POST['distance']; } ?> The book then remarks that this can be condensed onto one line, i.e. <?php if (isset($_POST['distance'])) echo $_POST['distance']; ?> but that doing so is rarely recommended. In the interests of learning best practice I decided to go with the first option of splitting out the if statement. However, I noticed that this causes issues in the resulting form in that the Distance text field contains large number of extra characters which mean that the is_numeric test always fails. This does not happen when using the if statement in a single line. Given that both syntaxes are supposed to perform the same, this is somewhat puzzling and I wondered if anyone else has encountered it or found an explanation? The full field creation is as follows in both syntaxes: <p>Distance (miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?> "/></p> <p>Distance (miles): <input type="text" name="distance" value=" <?php if (isset($_POST['distance'])) { echo $_POST['distance']; } ?> "/></p> Libby
  • Create New...