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. Looks interesting. Might try it around Christmas when I've got some more spare time.
  2. I hate that dumb backslash thingy. I think they should've went for spaces and called them imports like other languages. (Functionally, I see nothing wrong, but they just look ugly. This is two ways to implement the same in Java. import I.Look.Pretty.*; $z = new Nice(); /* --------------- */ $y = new I.Look.Pretty.Nice(); // Also pretty nice
  3. As said, the file does simply not exist where the script looks. This is what the error message says, and from expirence, these errors always comes from stupid mistakes... Try echo out the MYSQL constant or throw in a file_exists() there. In other words; do some simple debugging steps.
  4. The file mysql.inc.php is not found in the BASE_URI directory. Double check what the file is named, if you forgot to upload it, or if it's in another directory.
  5. Cool example. Love it. Some feedback for you. You should plan your class hierarchies good before you set them up. The question is whether or not all life forms are able to play or learn, and I don't think all species creates their own babies. (Even though I cannot guarantee it.) Love these kind of programming experiments.
  6. Wow, margaux. I did not think of that. You are 100% correct, though. You need to select a column to be able to order by it.
  7. Because it's just a constant holding a string. You need something called a resource, not a text string. A resource is created when the string (that is an URI to a script) is included, and the actual MySQL connection resource resource is created. The creation of this resource is happing inside the script you find by this URI. Maybe things would be easier to understand if we did this in config.php: $mysql = "path_to_connection_script.php"; $images = "path_to_image_folders"; define ('A_CONSTANT', "holding a string"); And a simple mysql script: $mysql_resource = mysql_connect('mysql_host', 'mysql_user', 'mysql_password'); if ( ! $mysql_resource) { die('Could not connect: ' . mysql_error()); } And this was your script: // Require config file holding variables and a constant require 'config.php'; // Echo out the contents of the variable and constant echo $mysql; // output: path_to_connection_script.php echo A_CONSTANT; // output: holding a string // Now require the resource require $mysqli; // require 'path_to_connection_script.php'; // Now we have the mysql resource in $mysql_resource $result = mysql_query($query, $mysql_resource); // Here we can use the resource to run a query What this means is that a constant and a string is pretty much the same thing. The constant is just a way for you to centralize where to put the require paths for your scripts. You could just use something along: define('MYSQL', 'path_to_connection_script.php'); // These two lines below are equal require 'path_to_connection_script.php'; require MYSQL; As you can see now, you are just getting this constant to use in your script. The whole point about a constant is that it is interchangeable. You can't define the same constant twice. This means that, if you require the config file, you are sure the MYSQL constant you find there will hold the value (an URI) needed for getting the mysql resource. Edit: This may seem complicated, but a resource is only another data type like Strings (text) and integers (numbers). The whole point is that for running a query, you need the resource as it holds vital info for PHP internally. You don't really need to know how it works on the inside. The resource is simply created when calling the mysql_connect() function, and then you are ready to roll with queries. Hope that helps.
  8. Remember that you can edit posts here. There's an edit button in the right bottom corner of your posts. That was kind of a weird error. Did not know you had to do that trick before right now myself. Glad you got it working.
  9. By looking at the MySQL manual, I think you need at % char before everything in the date_format function. Try this: DATE_FORMAT(registration_date, '%M %d%, %Y') AS dr The difference is "%," compared to just ",". You might need to add a space in "%d%,", but I'm not sure about that. Edit: I have tested now. It works both with and without the %-char in the query. Might be MySQL version specific, but I'm guessing there's just another small error.
  10. I would guess the query is not fine. mysqli_query() returns false when a query fails, and that's why the function is complaining about wanting an array. Instead of looking at the query, switch out your variables with values, and run it in something like phpMyAdmin. I'm sure you'll get an error there. Another good thing to do is to echo out your query before it's run. You'll see if the correct values/etc are there then.
  11. It's not a bug. You are not including/requiring the file where the function is located. This error is happening because the script can't find a function with the name of is_administrator(). To test this for yourself, try adding this right before where the function is called: if ( ! function_exists('is_administrator') ) { function is_administrator() { echo __FUNCTION__. ' was undefined.'; } }
  12. Surprisingly easy, yes. Had a lot of problems getting phpMyAdmin to work, though. Took my about an hour to find a blog post telling that "localhost" sometimes is buggy in OS X, so you need to use "127.0.0.1" instead. *facepalm* Sometimes, the world just won't give you a break... haha
  13. Programming is all about actions to data. When you have been programming for a while, you can identify that you need to do this and that to the data to achive a result. To take your calculator example. What does a calculator do? It computes answers out of operations performed on numbers, right? That's a pretty abstract description of a calculator, but it's a start. We must then decide what operations, actions, this calculator should be able to perform. Let's say we want to able to multiply two numbers, how can we code that? Let's make a simple plan: 1. We need a form with two HTML input fields. 2. We need to make sure the form is submitted by the user 3. We need to make sure both fields have valid values 4. We need to display error messages if not 5. We need to calculate the answer and display it to the user. This applies to all programming. My first programming teacher forced us to always write down all steps needed to achieve the wanted result. I think you should do the same. When you want to solve the problem, sit down and write a step-by-step plan on how to solve it. You don't need to follow that plan in the end, but you'll begin to see that planning pays off in the end. Hope that helps a bit.
  14. My order went right through. I had no problems. I suggest you do something with the feedback form, as the textarea is very narrow. Only thing I've noticed so far. I brewed myself a can of coffee and I'm looking forward to reading now. Edit: YII is up and running now. Found out OSX is shipped with PHP and Apache natively, so I activated that and changed my web directory to {user}/Sites/ some weeks ago. Had to alter the default timezone as it was not set, but other than that, everything went better than expected. Remember I ignored YII last time around because of that command line bs, but luckly I'v used it a lot recently.
  15. Use something along: if (isset($_POST['submitted'])) //Has the form been submitted? { // Strip dangerous tags $snippet_ref = htmlentities($_POST['snippet_ref'], ENT_QUOTES); // Add snipped to snipped array $_POST['snippet_ref'][] = $snippet_ref; }
  16. Congrats on the release. Bought it now.
  17. Remember that you can do so in PHP with arrays and objects too. class User {} // A simple, empty class class UserList { private $users = array(); // Can only add Users to the list public function add( User $u ) { $this->users[] = $u; } }
  18. Don't focus too much on micro optimization or best practices. Writing secure code is the most important aspect in my book. Then comes maintainability and easy to read code. You should focus on developing classes that don't do to much, are not tightly coupled and are easy configurable. What I mean by this is that you should be able to create a library and use parts of that whenever you need. (You do this just because you don't want to re-invent the wheel every time) The basics are the most important part of object-oriented design. It is absolutely a good idea to experiment with ideas on the side, though. I like to test out different things just because I'm curious. My suggestion would just be to experiment, ask questions and make sure to have fun. There's seldom a "the correct and absolutely best way" for things.
  19. — PDO is nice, but what are your needs? If you want to release a new open source blog system, then PDO would be that way to go. If you are just developing a personal, database driven to-do list, then you wouldn't necessarily need PDO's abstractions. It all boils down to your indented usage. — Not mandatory by any means. However, if you plan on using a MySQL database, then by all means use PHP's MySQLi extension if PDO is not really needed. Let's say MySQLi is mandatory when dealing with a MySQL database, and you should no longer use MySQL functions in PHP. Note that MySQLi is also written Object-Oriented, and all MySQLi functions comes with both procedural and object-oriented examples.
  20. You'll see this often in programming if the function uses well known functionality. It's much clearer with parameter hinting as you get the object type to. It's also more common if classes implement well-known interfaces to get functionality. Below is an example from Java that allows to to get input from a mouse. These types of interfaces can include 15-20 methods, so you would spare a lot of code by just using Event e. class MouseInput implements MouseListener { public void mouseClicked( MouseEvent e ) { } public void mouseEntered( MouseEvent e ) { } public void mouseExited( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { } public void mouseReleased( MouseEvent e ) { } } AnyEvent e is pretty much standard naming for events, as is Graphics g, Comparator cmp or Iterator itr. These of course differ slightly in difference languages, etc, but are pretty general well known names for the functionality they provide. These names are not "standards" by any stretch of the imagination, though, so feel free to use what you like.
  21. Please post both your scripts. The one displaying single posts, and the one displaying the list. I can't wrap my head around your explanation. Only thing might be the query for getting the list could need a second ORDER BY clause, something like maybe "ORDER BY views DESC, date_added DESC". (But I don't think your problem lies there)
  22. I can only answer the last one. This is because of variable scope. "var ajax", when defined inside a function, is only available there. If you define it outside function scope, or nest functions, the ajax variable will be available. This is a pretty important thing about Javascript, so I would recommend understanding it. (And it's not very hard eighter, pretty similar to how variables in PHP works.)
  23. The reason why your tables got dropped, is because Zen used a command like: DROP TABLE IF EXISTS table_name_here; This is standard behavior. The problem should not be related to the database, but to name collisions on tables. You should look into an option called prefix. With prefixing, you add something before all table names. That means you could have "zen_" before all tables related to zen. This is very common, and almost mandatory in many cases. As a general suggestion, always back up your database before running installations like these.
  24. Added a question about file uploading. (Not really JS related per se, sorry about that)
×
×
  • Create New...