Jump to content
Larry Ullman's Book Forums

Dimitri Vorontzov

Members
  • Posts

    72
  • Joined

  • Last visited

Everything posted by Dimitri Vorontzov

  1. Hey HartleySan, Merry Christmas and Happy Holidays! I absolutely understand everything you're saying, actually, what you're saying is pretty much another way of saying what I wrote in my question. I also understand (I think) the purpose of strcasecmp() function. What I don't understand is how the custom function can handle an array that has not two elements $x and $y, but an unknown number of elements $a, $b, $c, $d ... $x, $y, $z etc. I'm not sure if I'm formulating my question coherently, but I just don't understand how the structure of a custom function that refers explicitly to two items, $x and $y, can be applied to an entity that contains more than two items. As I said, I'm sure it's a silly question to a knowledgeable person, but I'm utterly perplexed. Would be grateful for clarification!
  2. Could someone please explain to me how this function actually does what it does? 1. If I get this right, the following function takes two elements of the top level array and compares the elements of sub-array alphabetically: function name_sort($x, $y) { return strcasecmp($x['name'], $y['name']); } According to the book, it will return a negative number if the first string comes before second alphabetically, a 0 if they are the same, and a positive value of the second string comes before first alphabetically. My questions: a) The function deals with two variables, $x and $y. But the array in the book has more than two elements! How does the function compare multiple elements of an array? It may be a very silly question, but I can't understand from the structure of the function how it can sort an array containing more than two sub-arrays. b ) What would happen to sorting the array by name if the values of the name were exactly the same (for example 'Stephen' and 'Stephen')? Thank you in advance for helping me to understand this!
  3. Hi Larry! So, from your explanation I deduce that the queries that the pattern in question is describing a string that begins with a single non-whitespace character and ends immediately after that character. So these strings should match the pattern: 'a', 'b', 'c', '-', '1', '`' -- -- and these shouldn't: 'aa', '2012', ' ', 'and so on'. Did I get this right?
  4. Thanks, HartleySan - but do you mind if I ask for a little more detailed explanation? First, I want to understand exactly what is this expression testing for. The presence of a single white space in the string, am I right? So, if I test something like: 'test string' against this pattern, it should return TRUE, correct? Or am I misunderstanding this?
  5. I'm in the middle of Chapter 14, Perl-compatible Regular Expressions. On Page 444, the following pattern is offered to test for presence of non-whitespace characters in a string: ^\S$ If I'm interpreting the chapter correctly so far, in the form created for testing subjects against patterns, pcre.php, I should enter this code inside a pair of delimeters, like so: /^\S$/ So, I've done that, and typed a string into the subject text area: Testing for whitespace characters. I received FALSE, so far so good. Then I type simply: testing And I received FALSE again! Suspecting that I may have messed up the code of pcre.php, I replaced my file with the one I downloaded from Larry's website. Ran the same two tests again, received same results. Either I'm missing something, which I suspect is the case, or the pattern is incorrect. Could someone please explain to me how to make it work or what I'm doing wrong?
  6. Thanks Antonio, I finally got it. And I appreciate your sharing the recommendation of using value/type checks whenever possible.
  7. Thank you, HartleySan, for such a thorough and detailed explanation. There's one thing I still need clarification with, though, and would very much appreciate it. If I'm understanding this correctly, stripos() function returns either a result, or false. The code on page 404 uses stripos() function: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } So if it's false, which is boolean, why would we need "!=="? I mean, it doesn't return 0, or 0.0, or "0" or "", or anything like that. I just returns plain old boolean false, correct? So why do we still need !== in that case?
  8. Hmm... Let me get this straight. So, stripos() function may return either some result, or false. We want to make sure it's not false. What's wrong with plain "!= false"? That would be making sure the result is not false, correct? Why would we need !== false? To check if the result is not boolean false? Is there any other type of false? I probably somehow misunderstood your answer, so please forgive me for not letting this go and asking questions that may be a little basic. (I'm a musician by education, not a programmer. ;-)
  9. I have a feeling I've seen such triple operators (!==, === etc.) in the code before, but I can't quite remember what they mean. On Pg. 404 (at the very bottom of it), this operator is used in the following bit of code: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } I don't think this has ever been explained in the book up to this point, unless I somehow missed such explanation. Could someone knowledgeable educate me, please?
  10. So, should this be considered as erroneous information in the book, and go to Errata?
  11. My question is mainly regarding Chapter 11, sub-chapter "Understanding HTTP Headers", Pg. 357 - but it also includes more general basic question. There's a line on Pg. 357: "Before getting to the example, note that if a script uses multiple header( ) calls, each should be terminated by a newline (\n) as in the preceding code snippets." Why? (The reason isn't explained in the book.) Also. I see that Larry is using \n quite liberally in his code. I want to understand the reasons. One of them, probably the main one, I guess, is to make the resulting HTML code more readable. What are other possible reasons?
  12. Excellent explanation, thank you very much, Antonio! (Larry, no offence, but that's the way it should have been properly done in the book.) A quick question though, Antonio: in your last query example, you have this: ( goal.player_id = player_id ) Shouldn't it be -- ( goal.player_id = player.player_id ) -- or is it a form of shortcut syntax I'm unfamiliar with? If the latter, could you please briefly explain? Thank you!
  13. What does GROUP BY clause do, exactly? For the life of me, I can't understand it from the explanation given in the book (Chapter 7, pg. 115): "When the aggregate functions are used with a GROUP BY clause, a single aggregate value will be returned for each row in the result set." That may be not Geek anymore, but it's not quite yet English. How can this be explained using simple Socratic examples? Do I understand it correctly that the GROUP BY clause breaks down into smaller chunks what would otherwise be one larger result? Or let me approach it from a different angle: in what way GROUP BY is different from ORDER BY? Thanks in advance for the explanation, as always!
  14. Antonio, you're saying that INNER JOIN and LEFT JOIN are the same - however, according to Larry's book, and to the StackOverflow post mentioned above by HartleySan, there's a difference. So, which is true? If my understanding is correct, inner join will return only the matching results; left join will return all the results from the "left" table, and those results from the "right" table that match the results from the "left" table, populating the rest of the results on the right with NULL value. Right join, if I'm understanding correctly, would do the opposite: get all the results from the "right" table with missing results on the "left" populated by NULL. Could the respected members of this Forum please confirm whether I get this right, or am missing something?
  15. Thank you, HartleySan. Would it be possible to see an example of the difference between inner and outer joins, using the forum database from the book? Motivated by my curiosity, I tried to run the queries from the "Outer Joins" sub-chapter, replacing left and right joins with inner joins, and they return exactly the same results, whichever type of join, right, left, or inner, is used!
  16. Can someone - (Larry?) - please explain in lay terms the esoteric Paragraph 1 from Chapter 7, sub-chapter "Outer Joins": "Whereas an inner join returns records based upon making matches between two tables, an outer join will return records that are matched by both tables, and will return records that don’t match. In other words, an inner join is exclusive but an outer join is inclusive." It's the second time I'm trying to go through this chapter, and the second time I stumble at that paragraph! Would be grateful for help from knowledgeable person!
  17. It's On in the phpinfo(), even though it's set to Off in php.ini - what am I missing? I'm using MAMP, I go to MAMP/conf/php5.3/php.ini - and there's a line in it that I personally typed: magic_quotes_gpc = Off Would appreciate your help.
  18. Thank you, Edward. Actually, I was pretty sure I disabled magic quotes - but probably I didn't do it correctly. Here's the line of code I used to disable them in php.ini: magic_quotes_gpc = Off I assumed, that line should have disabled them for all user-submitted data. I've got PHP 5.3, by the way. Still, the \' remain. Would appreciate more of your input. - Dimitri Vorontzov
  19. Hello Forum - hello Larry - - I'm working on a Mac, OS X Version 10.5.8. When I write a quote that contains an apostrophe to quotes.txt file, for example -- I've wasted my hours. - Leonardo da Vinci -- somehow a backslash appears before the apostrophe in the text file, and the same quote inside quotes.txt looks like this: I\'ve wasted my hours. - Leonardo da Vinci When I get the same quote from the text file via php back to the browser in view_quote.php, the backslash is displayed. The backslash also appears before double quotes: \"I've wasted my hours.\" - Leonardo da Vinci Why do backslashes appear, and what can I do to remove them? Thank you! - Dimitri Vorontzov
×
×
  • Create New...