Jump to content

ManiacDan

Staff Alumni
  • Posts

    2,604
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by ManiacDan

  1. Unfortunately that's the problem with tutorials like this. $this is an object-specific variable. It can ONLY exist inside a function which is inside an object. You don't know what I'm talking about. This is because what you're looking at here is a snippet of code that's designed to be sucked into an object function without your knowledge. Nobody has any chance of figuring out what your code is doing until you post the contents of the object, if you even know where that is. My personal recommendation is to not dive into a framework until you've learned the basics of how PHP works on your own. -Dan
  2. You're going to have to be more specific. You can write a function that will accept an associative array and will construct an update statement. However, you won't be able to write it to have intelligence about the data type for the queries without doing a SHOW CREATE TABLE and parsing it yourself. -Dan
  3. Well...what are you having trouble with? Page 41 of that book includes the instructions for arrays, use an array for question 1.
  4. If you're not fetching data, it won't be available. Turn on error reporting by putting this line at the top of your script: error_reporting(E_ALL); Using a framework generally isn't the best way to get started with a programming language, because you're not seeing all the "behind the scenes" things. -Dan
  5. The first one requires much more background information. Are you ready for arrays? Objects? Databases? The second one is very very easy. So easy, that the only hints we can give you is to do it for you. Echo the numbers, use the given operators to perform the calculations. -Dan
  6. That means $this->albums is not an array. Your code assumes that it is. This code is...weird. What kind of tutorial are you following? Did you do all the other steps up to this point? Is this a zend framework tutorial? -Dan
  7. There isn't much we can do other than to recommend the books and tutorials that helped us. I read "Web Database Programming in PHP and MySQL" (by O'Reilly) cover to cover, and I also read through the entire MySQL 5 manual, also cover to cover. Learning by doing is probably much easier for a dyslexic, but I can't say that for sure. -Dan
  8. Yes, that's because your posts are required to be moderated before they can be posted. I've approved your most recent post on SQL Joins. -Dan
  9. Auto-login cookies are generally created using a hash of four things: 1) Something they know that you don't know (password) 2) Something you know that they don't know (auto-generated hash stored in their user table, the microtime of their signup time, etc) 3) Something unique to their machine (IP) 4) A fixed salt that no user knows. Hash all those things, and store them in the DB along with their username or UserID. When they come back to the site, load the data for their user, and compare the generated hash on the server with the hash stored on their machine. If it matches, log them in. If it doesn't match, kill the cookie and kick them to the login page. -Dan
  10. Never store username and password in a cookie. If you must use a "remember me" cookie, do that, but don't actually store their password on their machine. Also, sessions rely on cookies, so you've been breaking your rule all along. -Dan
  11. Oh, so in addition to "keeping score" for the game itself, you're also "scoring" the teams in league play. Those should be kept in a separate table (or calculated on the fly). Don't give the team the 3 points until after the game is finished with. -Dan
  12. Wait...in what country do soccer games score in 3-point intervals? Why are you claiming your queries will update the wrong way...or something. Show the queries you're running. Your WHERE clause should be identifying these games based on a unique identifier (either an auto-increment ID in the database or by team/date), not by score. -Dan
  13. There's nothing else we can tell you aside from writing the query for you. UPDATE someTable SET field2 = LEFT(field1, 1); Also, there's no reason to ever do this, you're duplicating data and you'll only make it hard on yourself. -Dan
  14. Whichever ones are in the Zend_Controller_Action_interface constructor. Look into inheritance in OOP PHP. -Dan
  15. Zend framework doesn't have a problem with constructors, they're critical to OOP development. What makes you think it has a problem?
  16. James is right. You can also look into instances singleton classes, so you can just say DB_Object::getInstance() every time, which always returns the same memory location. -Dan
  17. This is what PHP is doing: echo 'a'.false ? 'b' : 'c'; //becomes echo strval('a'.false) ? 'b' : 'c'; //becomes if ( strval('a' . false) == true ) { echo 'b'; } else { echo 'c'; } -Dan
  18. Right...there's 1024 kb in a mb. Division is built into every language.
  19. With comments: <?php class Mysql { public function __construct() { //this doesn't go anywhere. Look into PHP scope. $mysqli = new mysqli( 'localhost', 'root', '', 'login' ); } } class Query extends Mysql { public function loginQuery() { //again, this does nothing and goes nowhere. $query = "SELECT gebruikerid FROM gebruikers WHERE gebruikersnaam = 'wouter' AND wachtwoord = 'test'"; } } class User { public function __construct() { $this->mysql = new Mysql(); } public function login() { //this function doesn't exist anywhere on any class, neither does $query $this->mysql->query( $query ); } } ?> -Dan
  20. Yeah...that was all kinds of wrong. class User { public function __construct() { $this->db = new Database(); } public function login() { $this->db->query( $yourLoginQuery ); } }
  21. print_r($something,true) instead of print_r($something). The second argument, when true, returns the item as a string so it can be used in an echo like this. Otherwise, the output is weird. -Dan
  22. Look into Snoopy(), it's a PHP class that masquerades as a browser, including proper cookie handling. -Dan
  23. You need to make the database connection a member variable of the user class: class User { public function __construct() { $this->db = new Database(); $this->db->login(); } } Also: the way I've described here is inefficient, look into the singleton pattern and instanced classes in PHP. -Dan
  24. There are no syntax errors in the code you posted. Are you sure you're looking at the right file? There's a filename in the error message, is that the one you're looking at? -Dan
  25. Make them full text if you want to search them. If you want to simply SELECT the ones that aren't fulltext, fulltext matching works on the WHERE condition. You can easily say: SELECT id, name FROM products WHERE MATCH(description) AGAINST('dog') -Dan
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.