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. What you need to do is joining the tables several times. I'll illustrate: SELECT threads.*, originator.user_id AS originator_id, originator.name AS originator_name, last_poster.user_id AS last_id, last_poster.name AS last_name FROM threads_forum AS threads INNER JOIN users AS orginator ON (threads.thread_originator_id = orginator.user_id) INNER JOIN users AS last_poster ON (threads.last_reply_member_id = last_poster.user_id) I might have used wrong column names, but that's the logic you have to use. Notice the aliasing on the joins. That's the key on how to solve such problems.
  2. If all objects created by with a DB wrapper implements a method such a compareTo, (or more like implements an interface that requires that method) object are extremely easy to sort. As the sorter only implements the looping logic, and the objects has comparison logic, all objects are sortable right out of the gate. That'll leave some seriously simple application code, like this: // Fetch all object from SomeClass $objects = SomeClass::fetchAll(); // Sort all object according to standard sorting $sortedByFirstName = Container::sort($objects); // Use comparators to sort $address = Container::sort($objects, new AdressComparator()); $telephone = Container::sort($objects, new PhoneComparator()); This is the magic of good OOP. As you have interface based implementations, you can quickly switch out and modularize logic. If you go for a String solution, you'll have to create a sloppy mess of very application specific logic into your classes, and you don't really want that. It's harder to maintain, easier to break, and harder to build on down the line. Separation of concerns is a very important principle.
  3. The parameter hinting requires an interface, not an object. That's a huge difference. What that basically means, is that you can add new sorting methods without affecting the actually sorter logic. That makes it a huge benefit over using simple Strings. Using String seriously limits what you can do with sorting here. I would disagree strongly with Jon here. It makes perfect sense to write code like this. Add this method to a DB wrapper, and it makes hell of a lot of more sense. Write five comparators, and you've modularized all your logic for sorting query results. The problem here is that you cannot take an example literally.
  4. You are not correct there, damcinnis. Laravel is using composer, and can therefor utilize packages from Symfony. It can be compared to using validation classes from the Zen framework in your own project.
  5. You need to give us some more if you need specialized help. Change data to something similar if you think it's sensitive. Other than that, you might use simple solutions such a in_array() or other solutions to check the data. Just save the results you fetch to an array and filter that.
  6. Aha. Keep sure you do your String concatenation correctly. The script is literally looking for a file with the name of '../uploads/{$_GET['image']}' right now. You must do one of the following: 1. Concatenate: $image = '../uploads/' . $_GET['image']; 2. String with variable support (double quotes) $image = "../uploads/{$_GET['image']}"; // Notice the double quotes If there's not any other errors, that should work.
  7. You revive an error message back. Make sure to read and understand it: That basically means that the variable $image is not defined where you are trying to use it's value at line 38 in the script show_image.php. As with pretty much all error messages in PHP, this one is also mostly self-explanatory. Without knowing your line numbers, I'm betting this is related to where you bind your GET variable "image" to the variable image. When you call this script, make sure you do it as show_image.php?image=image.jpg (a valid image value)
  8. What you must do is to use the full path to mysql.bin or create an alias to it (so mysql really calls the full path behind the scenes). This link will teach you a little more about it: http://glamanate.com/2013/04/02/xampp-mysql-command-line/ Xampp btw ships with a GUI program that will allow you to start Apache and MySQL that what. You can then access your server through http://localhost/ and PHPMyAdmin though http://localhost/phpmyadmin
  9. There should be no problem converting them. I know for a fact I've done this myself several times. The only problem I've had is when I've changed collations or decreased column size. Always take simple precautions like backing up your tables anyway.
  10. You NEED some sort of API documentation to be able to use it. For us, these numbers means nothing. You must find out what the numbers represent as stats, and then maybe build an array with those values. $player_name = $_POST['player_name']; // Or use GET $api_request_url = 'http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player='; $ch = curl_init($api_request_url . $player_name); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $api_str_data = curl_exec($ch); curl_close($ch); $stats = explode(",", $api_str_data); // Split data on String // ...Assign directly to new variables $strength = $stats[0]; $health = $stats[1]; // ...or build associative array with named key => value pairts $data = array( "strength" => $stats[0]; "health" => $stats[1]; ); I have no idea what the values actually represent, so they are completely random. Also, I found this for you. It seems to be some other part of the API. That's the kind of documentation you need to work with the API: http://services.runescape.com/m=rswiki/en/Grand_Exchange_APIs Edit: Also found this PHP API for you: https://github.com/ArminSupuk/Runescape-API
  11. How about doing the calculations on the input before you insert to the DB? Use the same variables as from your insert statement in your geolocation code, and insert the both data and the calculations in one step. Btw, I created a super simple class for handling Google maps geo data for my own site. Feel free to use it: - https://gist.github.com/thomaslarsson/5938143 You basically use it like this: include 'maps.php'; // Or what you want to call it $address = "Somestreet 7, 1000 postal, Country"; // As you would use Google maps // Use the class $map = new SimpleGoogleMaps(); $map->find($address); if( $map->resultExists() ) { echo $map->getAddress(); echo $map->getLatitude(); echo $map->getLongitude(); // You can simply do the insert here... } else { echo "Address not found"; }
  12. Antonio Conte

    Java Or C#

    No problem, Stephen. I don't think anyone is truly ready, with a few exceptions. Working in a software development company so much more than knowing how to code. You often need experience with revision control software, (GitHub, Subversion, etc) know your companies development methodology (Organization) and have certifications. This is mostly what you do the first few months you've been hired at a company from my understanding. You don't want to be that guy that broke the build. Hehe. I have never learnt as much about programming as when I took a course called "Algorithms and data structures". That course went over a single semester, and I had two courses prior to that. Basic Java and Object-oriented programming. You are 30 years and have waaaay better work ethics than kids my age. You'll have no problem doing the course if you study with regularity. Keep in mind that you also have to code to make the knowledge stick, especially for more advanced topics. Regarding books, I don't really feel qualified to give you any recommendations. I would check topics on Stack Exchange and check out book reviews on Amazon. I can also say that Beginning Java Objects seems like a really good book looking at the description, so I'm sure that's a good place to begin. If it's not critical for you to learn it now, I would ignore ecommerce and JavaScript, and focus on learning programming thoroughly. It'll be much easier for you to pick up those topics once the others are covered. If you still want to learn PHP, I would highly recommend Larry's PHP Advanced and Object Oriented Solutions by David Powers. The one by David Powers is one of the books I hold highest. Alsp, if you do start out with Java, feel free to send me a personal message on here if you need help.
  13. Antonio Conte

    Java Or C#

    Lots of questions here. They do absolutely benefit you, yes. Both C# and Java are fully object-oriented programming languages, while PHP supports both procedural (top-bottom execution of programs) and object-oriented programming. In my experience, learning at least one object-oriented programming language will help you immensely as a programmer on the whole. The main reason for this is because you will learn best-practice programming practices, and therefor extend your "toolset" of task you are able to complete. While you can be a developer without knowing how to code object-oriented, you are greatly limiting yourself. Jumping from C# to Java or visa-verca will also go pretty smoothly once you know one or the other. I can only speak for the situation here in Norway, but Java and .NET (Microsoft's C# framework) developers are very much in demand. In comparison, there's not many jobs for PHP developers there. I'm still doing my bachelor in computer science. From what I've gathered, you are not expected to be ready for work right after graduation. The companies I've talked to has an estimate of two to six months with several courses, certifications and training before you are ready. You will most likely start out as a tester or similar first. When you've mastered that, you'll get your chances to write code. In smaller companies, with smaller teams and projects, you are more likely to get a chance early on if you prove your worth. Regarding stress/expectations/pressure, I would say there's little of that. You'll start on the "ground floor", and has to prove your worth and work out how the company functions internally first. It does seem like consultancy companies expect a bit more from their workers here, but only those with top grades gets internships. That's my five cents. I'm based in Norway as said earlier, so it might be a little bit different over there. Norway is a very high educated country with lots of programming businesses, so I would guess it's pretty representative.
  14. You can't just change the connect function. You must switch completly to MySQLi or simply use MySQL. mysql_connect -> mysqli_connect mysql_query -> mysqli_query mysql_fetch_array -> mysqli_fetch_array ... And so on. Check the documentation as Jon pointed out.
  15. You need to do one of two things: 1. Declare $dbc as a global: function save_link($new_link) { global $dbc; .... 2. Pass $dbc to the function: function save_link($new_link, $dbc) { // Now $dbc is defined Your query seems absolutly fine. Try running it in PHPMyAdmin if this doesn't help out.
  16. Are you expecting more than one row in the result set? Your current code will allow 1 row and fail on anything else. That if-statement won't likely run, so I'm betting that's the problem. !== 0 or > 0 should do the trick. If that IS the point however, add a LIMIT 1; to the end of your query. It'll force a single result.
  17. artsyL: Just try it. I'm 95% sure assign the result of real_escape_string to a variable will solve your problem. I can exactly remember why, but it's worth a shot.
  18. Long time, no see Edward. Things good? I'm not really understanding what you are trying to do here, Jonathon. Do you have any logical way of dividing your groups? If not, develop methods in your model(s) related to the groups. Use that logic to do one of the following: a. ) Add a filter to your routing. Allow group x, redirect group y. b. )Add logic to your controllers. Allow group x, redirect group y. c. ) Add logic to your views. Post to loginModel 1 for group x, loginModel 2 for group y. No matter what you do, you need the kind of logic I'm talking about here. We have to little data to help you creating it if that's your problem, but I know it should work... Theoretically... If I've not misunderstood. Regarding to redirect to correct login on specific actions, add logic for that to. public method getUserLoginUrl() { if ( userIsMemberOfGroupX ) { return self::URL_TO_GROUP_X_LOGIN; } return self::URL TO_GROUP_Y_LOGIN; } Hope that helps a little bit at least. Get back to us man.
  19. The MySQL functions are deprecated. Try switching to MySQLi (i = improved) instead. $dbhandle = mysqli_connect('localhost', 'user****', 'password******', 'bluesmat_test'); if ( ! dbhandle ) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } I bet that is not really the problem, though. You'll find the db's name in PHPMyAdmin. Sure it's spelled correctly?
  20. I'm not really sure what you are asking here. You want the link to change depending on the user group? If so, render different views according to the groups, or add logic directly into the view itself. This is how I did rendering of navigation in CodeIgniter: // Core controller class protected function render_navigation() { if ( $user->isAdmin() ) { $this->load->view('nav/admin', $data); // Admin } else if ( $user->isUser() ) { $this->load->view('nav/user', $data); // User } else { $this->load->view('nav/guest', $data); // Guest } } Another example would be to pass the whole user object to the view and add some logical statements there. This should be pretty transferable to YII. I placed the method in my core controller, and render the navigation by calling it.
  21. My thought would be to handle this with different models / routes instead of different forms. Is that possible for you?
  22. The easiest way to check is viewing your sites source code. Find the link to your JS file and click it. See where the path is leading and change accordingly.
  23. The trick is to pass the variables into the functions as parameters. As an example, you'll need to pass the MySQLi object into a function - or declare it global as you're currently doing - to make use of it inside the function. Let's create an example: // Global way $mysqli = new mysqli(.....); // Create a MySQLi object function getUser( $id ) { global $mysqli; $result = mysqli->query(""); // Use $mysqli here. } // Passing variables $mysqli = new mysqli(.....); // Create a MySQLi object function getUser( $mysqli, $id ) { $result = mysqli->query(""); // Use $mysqli here. }
  24. You need to place your query into a String (quotes). It won't work without. $query = "SELECT COUNT(*) AS numberOfRows FROM college_notes WHERE link_code = 'CHES'"; $result = mysqli_query($dbc, query); // Result resource $row = mysqli_fetch_array('MYSQLI_ASSOC'); // Use something like this to get the result echo $row['numberOfRows']; Notice also that the $result variable will NOT hold the result from your query, but a result resource you can use to get it. It's as simple as adding one more step to your code.
  25. Yeah, at least functionally. I don't know how it works under the hood, but that's the effect. If it's hidden, it'll show up; if it's displayed, it'll be hidden. No problem. I'm not a JS expert by any stretch of the imagination, and helping others forces me to learn new things.
×
×
  • Create New...