Jump to content
Larry Ullman's Book Forums

Dimitri Vorontzov

Members
  • Posts

    72
  • Joined

  • Last visited

Posts posted by Dimitri Vorontzov

  1. I'm back to "Book 1" ("Repetition is the mother of knowledge") -

     

    - and I have a question.

     

    When I separate recurrent parts of the web application into separate files, to be included in the index.php, is it possible to use file extensions for included files other than .html, or .inc.html, or .php?

     

    For example, what if I want to save my header and footer as header.txt and footer.txt, or even header.jpg and footer.jpg. Would the code contained in them still work if I include them with modified extensions?

     

    Is this, or something similar, ever done, for example, as a security trick?

     

    Would appreciate your help!

  2. Trying to install phpDocumentor2, no luck.

     

    Would be grateful if you guys could talk me through steps.

     

    I'm on Mac computer, I have MAMP installed.

     

    Here's what I tried to do:

     

    1. Opened Terminal.

     

    2. Typed: pear channel-discover pear.phpdoc.org; (as per Larry's instructions from the book)

     

    Got the response:

     

     

    -bash: pear: command not found

     

    My second attempt:

     

    1. Logged in to MAMP using this line in the terminal:

     

    /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

     

    Got to the mysql>

     

    2. Typed: pear channel-discover pear.phpdoc.org;

     

    3. Got a response:

     

     

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pear channel-discover pear.phpdoc.org' at line 1

     

    What can I do to make it work?

     

    Thanks in advance!

  3. I've never seen this variation of the switch statement, could you guys please comment on it?

     

     

    switch ($language) {
    case 'German':
    echo 'Hallo, Welt!';
    break;
    case 'Italian':
    echo 'Ciao, mondo!';
    break;
    case 'Spanish':
    echo 'Hola, mundo!';
    break;
    case 'English':
    default:
    echo 'Hello, world!';
    break;
    }

     

    What surprised me is the last four lines:

     

     

    case 'English':
    default:
    echo 'Hello, world!';
    break;

     

    I thought the default should be set without mentioning the case before. Is that a legitimate way of doing things or just a typo in the book?

  4. Thanks, Antonio - but here's what' I want to know:

     

    1. How can I see the stored function (procedure)? For example, I'm accessing the database where I've just stored a function (using phpMyAdmin), and I only see tables that had been there previously, bot no stored function. Should I I do anything special to see that table where the function is stored?

     

    2. That stored function - am I correct to assume that once the function (procedure) had been stored, it will be available anytime as long as the database exists (that it. it doesn't have to be stored again whenever database connection is established from PHP)?

  5. I have a couple of questions regarding stored functions.

     

    1. Where are they stored? (Can I see a stored function using phpMyAdmin or mysql client? If yes, how?)

     

    2. Will the stored functions be available for as long as database exists, or only for the duration of the current database connection? (To rephrase it, should a custom function be stored just once, or it should be recreated every time the script runs?)

     

    Thank you for help, as always!

  6. Hello Forum!

     

    Asking yet another one of my typical questions.

     

    Do I understand it correctly that the underlying notion of the "normal form" databases is to eliminate repetition from every database, so as a result there's a bigger number of smaller databases?

     

    I'm asking this question because in Chapter 3 of the 3rd edition of this book Larry is using a database that contains repeated values in the same column:

     

    dbexample.jpg

     

     

    I also often find myself using databases like that, which seems to work perfectly fine.

     

    Am I missing something, as always? Do I understand the idea of the "normal form" database incorrectly, or should there be (if we deal with the example above) a separate databases for all UNIQUE, STANDARD and PO BOX zip code types, and a separate databases for HOTSVILLE, AGUADILLA, ARECIBO and so on?

     

    Would appreciate your input!

  7. Chapter 3 of the 3rd Edition of this book includes some work with a database of US zipcodes borrowed from US census bureau or some similar organization. The database is located here (the smaller database):

     

    http://www.federalgo...mentzipcodes.us

     

    Some of the latitude and longitude values in the database are empty, which can be checked by running the following query:

     

    SELECT * FROM zip_codes WHERE latitude='';

     

    Which outputs a number of results.

     

    (Showing rows 0 - 29 (648 total, Query took 0.0042 sec))

     

    Larry offers to replace the empty values with NULL, by running this query:

     

    UPDATE zip_codes SET latitude=NULL, longitude=NULL WHERE latitude='';

     

    But nothing happens!

     

    (0 row(s) affected. ( Query took 0.0993 sec ))

     

    Is there an error in the UPDATE query? What am I missing, why does it fail to update?

     

    Would be grateful for your help, as always!

  8. Thank you Antonio!

     

    But that wasn't what I was asking, actually. I totally understand the idea that no output comes before the headers.

     

    But my question is: can 1) a cookie be set after the header(s), or 2) should setting of the cookie be done before the header(s), or 3) it truly doesn't matter as long as both the cookie(s) and the header(s) are declared before anything is output to the browser?

     

    As I said from the beginning, it's a silly question, but I'm genuinely confused about that topic.

  9. Probably a very silly question to a knowledgeable person, but still:

     

    I know nothing should be sent to a browser before header() is sent there.

     

    I also know that nothing should be sent to a browser before a cookie is set.

     

    What if I need a header AND a cookie on the same page?

     

    Would they interfere with each other? Should a cookie be set before a header, or vice versa?

     

    Thanks in advance for your help!

  10. I think I was following the instructions very precisely, but the result isn't what it was supposed to be.

     

    Going to mysite/about/ doesn't land me on the about page (which I have created just to see what would happen, even though the book doesn't mention anything about creating it.)

     

    Repeated clicks on the links, modified as suggested in the book, result in URLs like this:

     

    index.php/about/index.php/this/

     

    index.php/about/index.php/this/index.php/that/index.php/about/index.php/that/

     

    and so on.

     

    I'd appreciate some help with this from a knowledgeable person.

  11. Well, HartleySan, this particular forum is supposed to be for the third edition of this book, so I think I was fair to assume that it's available to the members of the forum. I still appreciate your promptly reacting to my question, I just wish you had that book.

     

    Larry, being the author, should have a copy - that's why I invoked Him.

     

    My concern regarding your suggesting to show the entire code is that I'm not sure if posting the code from the whole section of Larry's book would be very welcomed by the author, but one the other hand, he can always delete a thread if it's revealing too much, so let me try (but only because you insisted, HartleySan!)

     

    So, first we define the two-dimensional array, which contains arbitrarily chosen id numbers for students as indexes of the outer array, and inner arrays of names and grades as values, like so:

     

     

    $students = array( 
    
    256 => array('name' => 'Jon', 'grade' => 98.5), 
    2 => array('name' => 'Vance', 'grade' => 85.1),
    9 => array('name' => 'Stephen', 'grade' => 94.0), 
    364 => array('name' => 'Steve', 'grade' => 85.1), 
    68 => array('name' => 'Rob', 'grade' => 74.6)
    
    );

     

    Then we define the function for sorting students by name (the one I was asking about):

     

     

    function name_sort($x, $y) {
    
    return strcasecmp($x['name'], $y['name']);
    }

     

    Then we define the function for sorting students by grade:

     

     

    function grade_sort ($x, $y) {
    
    return ($x['grade'] < $y['grade']);
    
    }

     

    Finally we output the array sorted by name --

     

    uasort($students, 'name_sort');
    echo '<h2>Array Sorted By Name</h2><pre>' . print_r($students, 1) . '</pre>';
    

     

    -- and sorted by grade:

     

     

    uasort($students, 'grade_sort');
    echo '<h2>Array Sorted By Grade</h2><pre>' . print_r($students, 1) . '</pre>';

     

    Now, back to my original question: the custom-defined function for comparing strings $x['name'] and $y['name'] is dealing with two strings only. The array contains more than two elements. How can that function sort the entire array, if it only compares two items?

     

    I am sure that the secret lies in the way uasort() function handles the result of the custom function, but I do not understand how it works, and am in need of an explanation. One way or another, I don't see any loops in that code...

×
×
  • Create New...