Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Posts

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. Jonathon is right: You might read the first few chapters of Zandstras book, but it is way more advanced than Powers'. You should really understand what Powers do before you take a close look at Zandstras book. I'm not digging Zandstras writing style, as he makes pretty basic things like Exceptions hard to understand. Therefor, wait with it, or read it but don't expect to understand everything straight away. As to patterns and such things, Zandstra is definitely a very good read. Please note that patterns are not like "the holy grail" or something that supersedes everything. Patterns are for solving common programming difficulties. You should be sure you need a pattern before deploying it. The book "Design Patterns" by Christoffer G. Lasater is also very good. I'm not done with it, but he explains hard-to-grasp patterns relatively easily, just like Larry is an expert on. The book is for Java, but for this kind of code, you won't have any problems understanding it or using it in a PHP-context. PHP and Java are very similar.
  2. It's not really a big thing. I can go to my profile and click find content from there. If this takes more than a few minutes, it's not worth it.
  3. $table_name = $_POST['table_name']; //Run ITG query $query2 = "SELECT COLUMN_NAME, DATA_TYPE, ORDINAL_POSITION, COLUMN_DEFAULT, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table_name'"; /* Set up and execute the query. */ $query1 = "SELECT COLUMN_NAME, DATA_TYPE, ORDINAL_POSITION, COLUMN_DEFAULT, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table_name'"; This is very dangerous. I do not know if mysql(i)_real_escape works with other DB-solutions than MySQL(i), but you should find some way to sanitize your input. ------------------------- To you problem: Start with Larry's code. Then, how about trying a function like array_diff()? I'm thinking like this: // It's now filled with data from both tables for the sake of argument $table1_data = array(); $table2_data = array(); /** Find differences between arrays: * Array_diff() returns a new array with elements from the first argument. (table1_data) not present in argument 2 (table2_data. * We also make this comparison vica-verca. I think you have to check both ways to be 100% sure. */ $table1_data_not_present_in_table2 = array_diff($table1_data, $table2_data); $table2_data_not_present_in_table1 = array_diff($table2_data, $table1_data); // Check if both arrays are empty. (They must be for tables to be identical) if ( empty($table1_data_not_present_in_table2) && empty($table1_data_not_present_in_table2) ) { // We have established table1 == table2 and table2 == table1. // They ARE the same. } else { // table1_data_not_present_in_table2 == An array of elements from table 1 NOT FOUND in table 2 // table2_data_not_present_in_table1 == An array of elements from table 2 NOT FOUND in table 1 } Hope this gave you something. Tricky problem you have. You might need to use some functions like trim(), but I think this is pretty close to a solution.
  4. Just for efficiency. If possible, means without to much hassle. If you really need an iterator, of course you should use one. I'm thinking the same way as with parameter hinting. You are allowed to specify an interface or a class there. I would really like the same possibility with methods. It was discussed for PHP 6, if I'm not mistaken.
  5. Is it redudant? Most likely Be strict when needed, but don't overdo it. Regular expressions are brute force, and therefor slow. Do enough to keep data integrity and prevent security holes, but don't use regular expressions on things like a forum post or a blog comment. Using them to check REQUIRED patterns, like mail adresses, password requirement and such. Security is often simple, because it has to be. Mysql_real_escape_string() practically makes queries safe. No need to bring the artillary ( reg. Expr. ) to do a trivial task.
  6. Sorry, of course you can. Did not spot the query. Jonathan is fight about the parantheses though.
  7. Your logic is wrong. That cannot switch like that. Try an equation with modolus ( x % y = 0)
  8. If you come from anorher language, like java, associative arrays works exactly as hash tables. Always an O(1) operation!
  9. Sorry to hijack the thread. The description fits just to good Can you customize the mobile version/template, larry? Would really love "my content" as a choice.
  10. Edward: oop is hard to understand in the beginnig. I struggled alot myselves, and you got to really study the code and read the explanations several times. This is not something understood in an hour. I would recommend you to Get object-oriented solutions by david powels (might not remember his name correctly). That is the best explanation of oop php i've read. Larrys book, the advanced one, also comes highly recommended. It is not an oop book, but every php programmer need to know that stuff top. You cannot create good classes if you don't know the good advanced solutions. I really like his array and recurssion parts. Sorry for any spelling mistakes. My iPhone wants me to write norwegian...
  11. Just a late reply here to. Using an iterator object is not efficient unless you work with large collections of objects. (N > 1000) traverse an array normally instead If possible. Php has such amazing array possibilities. Hash takles? That's an associative array! NullPointerExceptions? Never heard of. stacks or queques? Array_push/pop() and normal array! Php is really sweet sometimes. Give me return type hinting, and pretty please base type parameter hinting... I promise i'll never change language again!
  12. What are you going to use the hash codes for? Passwords? Searching for objects? You kind of have to specify the context you want to use them in.
  13. That is actually a common mistake to do this. HTML5 won't be standardized before around 2020. That is because (X)html 4.0.1 will become deprecated at that date. Html5 is not really something new. If anything, it's more backward-compatible than the 4.0-editions. That is the reason IE6 will handle it better. Coding Html5 is not really a switch. It has some new elements like header, section and the likes, but you are not required to use these. Html5 is more forgiving and more modularized than earlier version, that's why it's good. I have to admin I've not started to use the new elements or even the new doctype myselves. It might take some time still before I do this. I do have to agree with Jonathan about HTML5 in this context, thought. It's new, has new elements and would add a layer of complexety where it's not needed. (The book discussed.) Just wanted to clear up that the fact that is not and if/else scenario. HTML5 is just a small improvement if anything.
  14. It's time to give some fresh thoughts on this thread. I've learned a lot about object-orientation while writing Java in school. What PHP really lacks, is return type hinting, a solid base object the whole language* is constructed around, and other things like generic types. These things makes it much harder to code applications in object-oriented PHP, but not impossible. Back to the subject. Matt Zandstra's book is just GREAT. Heard of design patterns? This is one of the books that will teach you how, when and if you should use them*. It is most certantly NOT a beginners book. He introduces you to the whole OOP PHP approach, but others might make the switch more easily. When you've played around with objects, understood how they work and should connect your application together, THAT is the time to get this book. If you get this book, and find it hard to understand, leave it, read other books, then come back to it. Just great! For those who would like to learn about object-orientation, or just to learn more about it, David Powers book is a far better pick. He writes in a clean and easy-to-understand fashion, and his examples are good. This will give you an understandment for wordings like inheritance, abstraction, interfaces and how to write clean code. His extension of the DateTime class is great, and I'm using a slightly modified version of this in all new projects. I would recommend both these books warmly. Object-orientation is not something magical, like I think Larry said. Even programmers like Zandstra say procedural code is the right thing to do on occations, especially as PHP is not object-oriented per say. Object-orientation is the art of gathering usefull functions (aka procedural functions) into groups of classes that interacgt with each other. It's not something magical that makes you write 100 times better code.
  15. I've never used ENUM with a Database, but it does make sense from what I've learned by JAVA. After reading about ENUM in the MySQL doc, I believe this is very good way to solve your problem. If Enum doesn't do the trick, build a "legal values" array and check input with in_array() or something like that.
  16. Did not notice that, Paul. I didn't know select had a multiple tag. You learn something everyday, huh? Your code also makes sense now. Good solution. Is there any reason for using isset(), though? in_array() will do that job on it's own, or am I miss something here? Just curiosity. ----------- To TS: How about checkboxes? It just makes more sense if you first give the user an opportunity to select several values. This is done exactly the same way as with multiple option tags: <input type="checkbox" name="checkbox[]" value="a"> <input type="checkbox" name="checkbox[]" value="b"> <input type="checkbox" name="checkbox[]" value="c"> <input type="checkbox" name="checkbox[]" value="d">
  17. You cannot use if/else inside an echo. Paul's code might work, but here is the way I tend to do this. foreach ($options as $service) { if(isset($_POST['selService']) && $_POST['selService'] == $service) { echo '<option value="'.$service.'" selected="selected">'.$service.'</option>\n'; } else { echo '<option value="'.$service.'">'.$service.'</option>\n'; } } Hope it works. Btw: Use the code formating tags when posting code...
  18. Try: LEFT JOIN users ON users.userId = comments.userId
  19. You use C and U as table acronyms. FROM comments AS c LEFT JOIN users AS u Where does m come from? CONCAT(m.firstName, ' ', m.lastName) AS author
  20. Remember to use a WHERE clause in your queries. Else, every row will be updated this way.
  21. You retrieve it through the select name element. Skip using a variable there, and call it something like <select name="date">. You get it normally through post like $_POST['date']. This will retrieve the value.
  22. Sorry about that. Had to catch a train, and I must have overlooked that you used it. - A suggestion. Have you tried to run the query using something like phpmyadmin? - echo mysqli_stmt_errno($stmt) will give you any error messages or the string "zero" if none. Looked at your site. I can see both title and content on the links described. Did you solve this?
  23. Use mysqli_stmt_bind_result. mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $title, $content); while (mysqli_stmt_fetch($stmt)) { printf ("%s (%s)\n", $ti, $content); }
  24. Great tip, Josee. You should always use the mb functions (Multibyte String Functions) if they need to work with Unicode characters.
×
×
  • Create New...