I need skillz
February 18, 2008 11:15 AM   Subscribe

I have two weeks to learn PHP. Help me make a plan!

Because my library job is ridiculously awesome, I'm being given two weeks to devote myself to learning php. This will be time otherwise unfettered by work concerns; I'm even staying out of the library to help make that happen.

Previous AskMe questions were helpful in a general sense, but I also want a reality-check on my expectations. I have no programming background. I have a handful of self-taught html and css skills. I am fearless in the face of technology, and I have a well-honed librarian's ability to find answers when I have questions. What do you think I could expect to accomplish in 2 weeks (80-ish hours) of work? What resources would you recommend, particularly in online tutorials? Are any of them worth paying for? (I've seen prices from $30 to nearly $1000; I probably have some library money at my disposal, but nothing approaching the upper end of that range.) Anything I'm completely missing in my naive enthusiasm for this project?
posted by donnagirl to Computers & Internet (20 answers total) 39 users marked this as a favorite
Php.net is your source for php information. I use it nearly every day (mainly because I always forget how to get a date in the YYYY-MM-DD format).

Then, I know you say you don't have programming experience but PHP in a Nutshell is a quick and dirty guide to the language.

A bit more readable is Programming PHP.

I own a lot of PHP books, and these have been the two most useful. If the section in one book is confusing, try consulting the same section in the other book (for example, PHP in a Nutshell has a better explanation of Object Oriented Programming).
posted by drezdn at 11:23 AM on February 18, 2008

Also, I haven't used it, but everything else they do is cool, so try W3 Schools PHP tutorial.
posted by drezdn at 11:26 AM on February 18, 2008

One last thing, what exactly do you want to be able to do with PHP? That will kind of determine what you can accomplish in 80 hours of learning.
posted by drezdn at 11:28 AM on February 18, 2008

Response by poster: I'm looking to be able to code simple applications that might be useful to library users. An example would be a citation creator, where students input author, article title, journal name, etc, and get back a citation formatted for APA or MLA style bibliographies - see NCSU Libraries for an example. Eventually, we'd like all our subject guides to be dynamically generated, so that would be a larger project once I've gained some confidence. Thanks for your help so far!
posted by donnagirl at 11:39 AM on February 18, 2008

Response by poster: And to clarify, we have a programmer on staff to do any really heavy lifting, but his time is in high demand. I'm looking to be able to take some of the smaller, lighter projects off his plate.
posted by donnagirl at 11:44 AM on February 18, 2008

Best answer: I think you need to narrow your focus. The goal in two weeks should be to get comfortable with PHP and the other, generally critical parts of a typical PHP deployment - including MySQL. It will take six months to a year (assuming you're using it semi-regularly) to get really knowledgeable.

I'll defer to the recommendation as to the books above.

However, I think the best way to learn is to try to build something. Take a really simple concept- say a web page that lets you add,edit,delete a simple todo list. Then, dive in - google is your best friend, and as someone else mentioned, php.net.

1. Use mysql's website to learn how to build a simple database and a simple table. put some 'fake data' in the table.

2. Look up how to build simple HTML forms. Since you have some HTML experience, go ahead and build a page that lists some sample todo items without any PHP.

3. Then use the PHP.net site to learn how to load data from mysql, and learn how to echo it - use the php books to read up on for loops, etc, and get familiar with the language.

Then do the same thing for a simple form that posts up new todo items - those books will surely have good examples.

The best way to learn is to get your hands dirty. good luck.
posted by carlodio at 11:44 AM on February 18, 2008 [1 favorite]

For the citation creator, you'll want to pay special attention to the section on form handling in php books/tutorials then.

One last book to recommend, it's a good idea to read through Essential PHP Security after you've developed a good grasp of the language. It's only a hundred pages, but it'll prevent huge problems later.
posted by drezdn at 11:47 AM on February 18, 2008

Best answer: The citation generator sounds like an excellent opportunity to learn to use a template engine. A template engine is used to keep your nuts and bolts PHP separate from your presentation stuff (html and css) so that things are neater and so that maintenance issues are partitioned along the logic/design line. That way you're not forced to work gingerly around your logic chasing down display issues and you're not forced to skim a bunch of distracting presentation cruft debugging programmatic flow.

Smarty is not an ideal solution to the problems template engines seek to solve but it's so ubiquitous I'd be hesitant to suggest anything else.

There's no need to involve a database for that application, but you'll need one for the subject guides. Don't let anyone talk you into using MySQL, ubiquitous or not. PostgreSQL or Firebird are exellent choices, and they all share the same PHP interface if you learn to use the versatile PDO class. All these database managers implement the same SQL standard, but with varying agreement with the actual chapter and verse. Any how-tos or tutorials you find tailored towards one database manager are going to be broadly applicable to any other with minor caveats, and with time you'll come to quickly spot the things that need a bit of massaging to fit in with your database manager flavor of choice.

Having mentioned how-tos and tutorials I have to also mention that the PHP community is a minefield of kids, hobbyists and the insane, and a lot of frankly disasterous code is upheld and passed on as the exemplar for the next generation. Be very wary of things you find on forums, on blogs, or the user comment section of the PHP manual.

These sound like great projects to learn with. Most PHP work comes down to writing the "middleware" glue between some templates and some data, so you'll come out of this with a solid foundation on which to base future projects. I wouldn't count on getting very far into SQL in 2 weeks, but you should be able to knock off the citation machine project and find your legs with regard to PHP in general.
posted by moift at 12:21 PM on February 18, 2008

I am sure you can get the basic hang of things in two weeks. There are lots of books avalable out there and many walk you through the creation of a project. Hey you work in a library, you may not even need to buy one. Some one previously recommended php in a nutshell and I wanted to comment on that. The nutshell books are nice for looking up bits that you dont remember or are not sure how they quite work, but they are not so good for learning the language in the first place. You don't need that early on. Maybe later when your are better aquatinted with the language.
posted by d4nj450n at 12:31 PM on February 18, 2008

I agree with the idea that you need to pick an idea and start by building an application based on the idea. Trial by fire is the best way to learn a programming language. You are going to struggle alot at first, but if you keep hacking at it, you'll make headway.

I also agree that you'll need to get your feet wet into the database world. SQL will be your friend.

Most web apps revolve around a similar theme: a table that lists information in the database in grid format (let's say its a real estate app, so this table would show all houses being listed) and a form page that displays and lets you edit one row in the database (a single home entry perhaps, how many rooms, square feet, etc.)

So here's what I'd do:

1. Find your hosts PhpMyAdmin and set up a simple table. Add several rows of sample data.
2. Use PHP/SQL to pull all your data from the database and show it on a table.
3. Allow the user to click on one row which takes them to a form page and allows them to edit the sample data.
4. Back on the table page, give the user the option to create a new entry. Create a new form page or figure out how to reuse the one you used for editing.

If you can find a tutorial that walks you through the above, you'll be miles ahead in getting started.
posted by bprater at 1:05 PM on February 18, 2008

I learned PHP back in the day with a book (one of the few really good programming books I've ever bought-- helpful to the newbie and useful later on (circa 2001)) and a desire to copy the functionality of Metafilter. Don't ask programmers too many questions up front; they'll have a tendency to give you a more complete answer than you need/ can use. One thing I would suggest: don't forget about the database side of things (unless you're not using one). On Windows, HeidiSQL makes it easier to get a feel for what you're doing in the database (if you're using MySQL).

Spend the first bit of time getting a stable environment set up (web server with PHP, database). If you already have that, you're ahead of the game.
posted by yerfatma at 1:09 PM on February 18, 2008

Best answer: I'd simplify this by not learning a database (such as MySQL) right now. It's a big part of PHP web development, but it's also a world in itself. You can easily get to be proficient enough with the language itself in 80 hours, if you really put your nose to the block, but you won't have any sort of feeling of how to do a larger database-driven project. That kind of stuff takes months/years to learn to the point where you don't screw stuff up majorly. A citation creator should be well within your reach, though.

It will also really help to have someone that knows PHP well so you can ask questions. There's usually many ways to do one thing, so you'll usually be able to hack your way through a problem, but having someone around to say "well, yes, that works, but ____ way is more elegant, shorter, and safer" or "whoa, I don't know why that works, but you should never use it again, because ____." You'll learn that stuff eventually, but that kind of immediate response is what takes the months & months of doing to get.
posted by devilsbrigade at 1:25 PM on February 18, 2008

I just learnt the basics of PHP and mySQL through distance education - my last assignment went in on Thursday. It took about 60 (4-5 hours per week, for 12 weeks) hours all up. Doing all the exercises in the book really made a difference, because even if you understood how it worked, you had no idea how wrong you could get it, until you did it. Eg END; must always be on the start of a line, even if everything around it is indented.

The other thing, if you've never ever programmed, and I sort of had, if you count Basic way back in the 80s, I think you need to have a quick look at flowcharts or whatever the groovy kids are using nowdays to indicate the process of a program. It's really invaluable for creating a visual to-do list that makes sense and is logical. Understanding that will keep you from (hopefully) making endless loops and other silly things.

The book I used (along with my university's study guide) was Nat McBride's Teach yourself PHP which was fairly good except for some typos in the code (great!?!) and a poor habit of starting the code with the shorthand code for starting php that I can't show you here instead of the full and appropriate code which I also can't show you.

Lastly, the site drezdn linked to, php.net, is invaluable.
posted by b33j at 1:31 PM on February 18, 2008

Seconding that you shouldn't bother to learn a database, it's too much conceptual & management overhead for a two-week experiment. You may find it easier to work up to the database by reading and writing simple text files with data. That should introduce plenty of basic concepts like the client/server request/response loop, filesystem permissions, accepting user input, and blatting out HTML responses.

Smarty (mentioned above) is great, maybe not entirely necessary yet. PHP itself was originally designed as a light template language for the web, and it's easy to hit the ground running wihtout worrying about any best practices like logic/presentation separation, etc. The need for those things will make itself clear once you're over the excitement of a working application and have a few spit-and-chewing-gum projects under your belt.
posted by migurski at 1:39 PM on February 18, 2008

I can't believe no one has mentioned Practical PHP yet.
posted by IronLizard at 2:28 PM on February 18, 2008

Response by poster: OK, you guys are awesome, as always. I marked a couple preliminary best answers that gave me encouragement and focus, and I'll be back during my 2 weeks of Camp PHP (March 3-14) to mark those actual resources that I found most useful. Thank you!
posted by donnagirl at 2:34 PM on February 18, 2008

Best answer: I've found it best to deal with this type of situation in stages; this is particularly relevant because this is a first-time programming project.

First stage: Environment.
Learning a programming language is not simply about the syntax or idioms, its about figuring out your environment: how to compile, read logs, install modules. A friend will come in very handy during these steps, particularly someone with sysadmin skills. This can't be overstated; you're trying to learn a language, and if you spend the first week figuring out where your error_log is, you've wasted that week.

Second stage: Building blocks.
Once you have an environment, I'd go right into some prebuilt (demo) code; you can download stuff like this from tutorial sites. Get that code working, and then start messing around with it. Most likely a good deal of the stuff you'll be dealing with early can be figured out inside a fairly limited framework, so start cutting and pasting and tweaking and see what works. Again, this works best with a talented friend, but not required.

Third step: Basic constructs.
Now its time to hit the books. You've got a working environment and some basic programs, now its time to read some tutorials about logic, conditionals and functions. Its also time to learn about data types. With this knowledge you'll know how to architect basic programs, and have a reference set of documents. Again, a talented programmer friend will help out here as well, but not required.

Fourth step: On your own.
Now that you've got the building blocks, its time to figure out how to read the language API, and then employ that to start building out tools of your own (start small - 15 lines of code or less).

The essential takeaway here is that learning programming (or a language) is least about the actual process of coding. It's really about mastering your environment, pulling together the requisite building blocks, and getting a sane debugging space. These steps are very amenable to friend intervention. Once you get to coding, its relatively simple and logical; as you'll progress and move through languages you'll find yourself saying "I bet there's a function for this". But in the beginning, its all about the building blocks, the least of which is coding. The fancy stuff can come later. Good luck!
posted by fstutzman at 4:47 PM on February 18, 2008 [1 favorite]

When I started learning PHP many years back, my best resource was webmonkey. Loved it for its humorous, beginner-friendly style of writing. Perfect for newbies without prior experience in programming. Although not updated as frequently now, the tutorials are still quite relevant because the foundations are still pretty much the same.
posted by arrowhead at 6:37 PM on February 18, 2008

With any new language it's important to be very organized in your approach. Keep backups when you get things working, so you can go back and compare if things go sour. Professional programmers use a revision tracking system like CVS or Subversion, but you can just take zip backups and give them meaningful names. Stay confident. I personally enjoy coding in PHP and find Java more hostile to getting things done. That is not to say that PHP does not have its pitfalls, but I just personally think if you do your homework PHP will give you results. Also, a debugging trick I learned a long time ago is to say "what variable would I want to see the value of right now to tell me why this darn thing isn't working, and what would seeing its value tell me?". Half the time I figure out the answer just from that deep thought, the other half of the time I put the echo statement in and learn something new about the language.
posted by forthright at 8:28 PM on February 18, 2008

The folks who have mentioned MySQL are on the right track. Learning PHP as its own thing will not be of much use to you if you don't have the database skillz behind it.

As stupid as it sounds, I highly recommend PHP & MySQL for Dummies. I am not a fan of dummies books, as a rule, so please do not take this recommendation lightly. But I was in a similar, though more desperate situation a few months ago and was able to create a really decent web app and, in the process, learn just about everything I need to know to get myself quite comfortable with PHP. I suggest working through this whole book, step by step, with the example code you can download from the Dummies site. And, certainly, supplement with the wonderful sites mentioned above, like PHP.net, that I hope you've already bookmarked.

I want your awesome library job, btw.
posted by scolford at 1:16 PM on February 19, 2008

« Older A rose by any other name...   |   Toxic Inhahler Newer »
This thread is closed to new comments.