Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Content Count

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. Jon or Larry might give you some feedback on the regular expression. If you only want to solve the problem, you could consider using a function like strpos() instead. Something like this should work excellent: $subject = "AStringWithA spaceInIt"; $pattern = " "; if ( strpos($subject, $pattern) === true ) { echo "Pattern found in subject"; } else { echo "No pattern found in subject"; } The function is not binary safe, that's the reasoning behind checking for === true. Hope that helps.
  2. You HTML output is incorrect. Look at this: <td>First Name</td> <td><input type="text" name="first_name" id="first_name" size="45"/></td> </tr> value=<?php if (isset($_POST['first_name'])) echo $_POST ['first_name'];?> The code should probably be: <tr> <td> <input type="text" name="first_name" id="first_name" size="45" value="<?= (isset($_POST['first_name'])) ? $_POST ['first_name'] : ''; ?>"/> </td> </tr>
  3. There are sure benefits to both methods. You can of course also move methods into a new class if they start to grow a lot in number. You'd then simply make the constructor public (You can do that anyway if you prefer) and use the class name instead of self. Glad I could help out.
  4. Are you sure you've connected to the right database and are using the correct host? You might use a "user" table residing in another DB that doesn't have a "first_name" column you try to query against.
  5. There's no definite answer here. It pretty much depends on what you need to do with the class. There's a principle called the "Single responsibility principle" I really like. It says that a class and each method should only have one responsibility. This can often be a bit tricky to define, but "representing a User instance" and "creating a User instance" is so different they should probably be handled by different classes... So, how can do we do that? 1. Create a model: Create a new class that takes the PDO object in the constructor and add methods for operations such a CRUD. On Select-ty
  6. if ( validateEmployees ( $_POST['employees'] ) { echo "All values are Integers greater than zero."; } else { echo "Invalid data"; } function validateEmployees( array $employees ) { if ( empty($eployees) ) { return false; } $filtered = array_filter($employees, 'isPositiveInteger'); return $count($employees) === $count($filtered); } function isPositiveInteger($value) { return is_int((int)$value) and 0 < intval($value, 10); } Something like this could work. Play around with something similar until you get it right. Hope it helps.
  7. You should be able to get them by a foreach. foreach ( $_POST['employees'] as $key => $store ) { echo "{$key}: {$store} <br>"; } The same principle applies for computers. The one thing you might have to do is to assign the store key instead of the name, but I had a little problem understanding what you really try to do here. Hope this helps out.
  8. Jon: Very interesting. I've started using a scratch-card when I program, and any thoughts that pop up in my mind is written there instead of switching focus. I think our approach is much more similar than anyone of us could guess from the get go. I think you are correct in your assessment of TDD in general. Nothing is magic, and everything requires dedication and work, no matter which route you go. My conclusion when it comes to programming, is that simplicity is often the most important aspect. You should understand your code after two months away from it and be able to add functionality
  9. I agree with you on almost every point. I also think you are a great coder, and there's no mistake you produce few bugs. The tests in questions are unit tests, yes. I don't really perform functional testing unless you count confirming behavior be looking at the output result. The statement regarding test quality versus code quality is spot on. Testing can absolutely give you a false sense of security, and that is why I focus more on the process of TDD than the actual unit tests themselves in my post. TDD helps me keep focused on a single class at a time, where I normally get scattered-brai
  10. You should be able to generalize Jon's solution and make it viable for any number of values. Instead of setting explicit keys in the last array, you can use <select name="computers[]"> and <select name="stores[]"> in your HTML. You can then foreach () upon the $_POST['computers'] and stores array to loop trough all values.
  11. It's mostly related to test stubs and the nature most static methods are written. Static code is procedural by nature, and while that is not bad in itself, you cannot (easily, with a few exceptions) mock that. The point of OOP is to create modular classes with few hard dependencies, for re-usability and easy refactoring. A mock is basically a replica of object functionality. If your class expects an object implementing a Deductable interface, you can make a mock with the methods required. While that may seem illogical, you wouldn't be able to delete the class Deductor if your tests relies
  12. Jon: The general nature of a framework means it will most likely have more features than you need. You must also keep in mind that due to the composer based nature of the package, you will dynamically only load what you need. Laravel provides you with session management from anything from a database to memcache, but won't utilize the whole package in each go. I just think I should clarify that. Matt: Static is generally bad, unless you deal with pure helper classes or helper methods. Laravel and YII both lies a little bit to you in code appearance, as you are actually talking to a Facade c
  13. I would recommend you to use something that already exists. Laravel is component based, and you can find components under the Illuminate namespace. Illuminate\Session will abstract and secure Session handling for you. You can find it on packagist.com and install it using composer.
  14. Edit: Looks like I posted too soon. Seems like "Canada/Atlantic" is depricated [link]. The timezone might not be available. I'm pretty sure you should be able to find another one that fits you in the America section of the timezones: http://no2.php.net/manual/en/timezones.america.php As a general suggestion, you should also look out for exception: try { $dateTime = new DateTime("INVALID"); echo $dateTime; } catch ( Exception $e ) // Error handling { echo "Invalid time"; } You can solve this a couple of ways. 1. Edit your php.ini file: (location depends on operating sy
  15. I know you didn't ask me, but I use Windows at my stationary at my dorm and a Mac for Travel/at home. The Windows machine runs Windows 8, and is a custom built beast of a gaming machine, while my Mac is a normal Air. I find it easy to switch between the two, but it has required some configuration. Especially the command line required a lot of aliasing, but I've set up a .bashrc on my windows machine to have Linux commands for whatever I do. That's really the biggest difference. As work tools, I've switched to NetBeans and Sublime from Eclipse recently. All are available for both Windows an
  16. Still works here in Firefox 26.0. What browser are you using?
  17. Are you getting error messages here? If so, please share them. By the looks of it, you should replace "INTO" with "AS" in your subquery, but I don't I don't know if that's your problem. It's most likely a syntax error though. You must obviously have data in both orders and order_contents for this to work. $query = "UPDATE orders SET total = (SELECT SUM(quantity*price_per) AS subtotal FROM order_contents WHERE order_id = {$oid} + $shipping) WHERE id = {$oid} "; Hope that helps you out. If not, we need some more info from you.
  18. Are you sure your Live server PHP version supports password_hash()? It ships with PHP 5.0.0, but won't be available in lower versions of PHP. You can check this by adding phpinfo(). If it doesn't exists, you'll need to upgrade PHP or switch hashing function. Edit: You can also check for errors by adding these lines to the top of your script: ini_set('display_errors', 1); ini_set('error_reporting', -1);
  19. Glad you take it that way Jon and Matt. As a non-native to English, the sublities in communication is harder for me textually. No need for an apology to me. It looks like we still have a communication breakdown though. I'm not talking about coding in reference to interfaces, but to the graphical UI that drives the data flow around. Does that make more sense?
  20. That's why I pointed out it might be an interface issue rather than a programming issue at that. I also don't know Matt's programming skills and how you guys split the work-load. I'll just underline I'm not trying to insult anyone. Dismiss my advice if it's not appropriate/needed. Nice to hear it's going fine programming-wise though! To explain further, have you thought about separate interfaces and/or forms for managing stations? Instead of both adding and deleting stations in one fell-swoop, you might benefit from dividing the two operations. That might also be a easier mental model
  21. I think that too sounds like a design issue, either in the user interface form designs or in the database. Could you possibly explain your problems a little more in detail? The best thing you can do is to make sure your related inserts/updated/deletes are done as a single operation. You can do this by concatenating Strings into a single query or imploding an array and combining inserts and select queries. (Look at WHERE key IN (a, b, c) To make sure everything works as expected, you should go with transactions. With the right level of modularity and high-level abstractions, the code sh
  22. Make sure you don't feature-creep your project. "Nice-to-have"s easily becomes "might-be-useful-some-day"s. Start out by gathering good requirements and make a solid plan with good milestones for development. Start out bare-bones and add the basic functionality first so you can quickly view some result, then refactor your code and add nice-to-haves later. It's very easy to become distracted and hung-up in specifics along the way. Besides that, I don't really feel I can contribute in a meaningful way.
  23. Matt: I think you should read a little bit about interaction design. It will give you some tools and a process for finding the best possible UI design. I've very successfully used human-computer interaction to design interfaces for a car retailer system before. If you have the money, you could of course hire someone to do the job for you. Bad cognitive models in a UI is often a reason system don't get used, no matter how good they are. As for my suggestion, I was actually thinking of a adding a single, toggle-able button on each station and sorting the rows into groups of "selected" and "n
  24. I think most of the complexity here is related specifically to the checkbox design. If you changed the approach to something like toggled buttons with "Would work at" / "Not interested" and updating the list using AJAX, the design would be dead simple. While DB performance is important, this is not really expensive operations to perform. A series of small inserts/deletes might also work faster than a larger transaction. Due to a much simpler design, I would prefer this solution myself. (And have done in the past) The array solution should also be viable. Unless we are talking tens of thous
×
×
  • Create New...