Best way of learning PHP and Javascript etc..?

Caporegime
Joined
3 Jan 2006
Posts
25,010
Location
Chadderton, Oldham
Hi.

I'm trying to learn PHP and Javascript, I am wanting to become good enough at it so that I can create fully functioning dynamic websites but also if I use code that I've not done myself I full understand it and can modify it.

I know about W3C Schools, I have being going through them, but I find myself thinking that half of the examples that the tutorials are based on are performing useless things, I can't ever see myself needing to use an array to populate a form based on a persons details that have already being wrote into the javascript?

So are the W3C Schools tutorials really the best way to start? I find it really hard to grasp and when I struggle to do something like refresh an image on a page within a div (not managed to do it) it frustrates me as even an average coder could probably do it with ease, just makes me feel useless.


Thanks.
 
I set myself a project to complete and bought some php and javascript books. a lot of reading, googling and questions later I am 90% complete and have learnt a hell of a lot.

Trying to learn without a goal or website to do, for me would be very hard.
 
Hi.

I'm trying to learn PHP and Javascript, I am wanting to become good enough at it so that I can create fully functioning dynamic websites but also if I use code that I've not done myself I full understand it and can modify it.

I'd just recommend you get on with it and write your sites, but it'd take a while before you were relatively decent if you don't have any other programming knowledge.

After you've done a project, maybe take a look at how frameworks differ from your own implementation, or some larger opensource work. You won't find a lot of decent design decisions by googling code and gluing it together, but its how I started writing code...

I know about W3C Schools, I have being going through them, but I find myself thinking that half of the examples that the tutorials are based on are performing useless things, I can't ever see myself needing to use an array to populate a form based on a persons details that have already being wrote into the javascript?

Depends if you want your site to still function without javascript, personally I'd rather mines do, but in the days on ajax we're seeing a lot more sides that are practically useless without jacascript. The question is how you handle that.

On the validation side (inputs and such) you have to assume 100% that your JS based validation will be bypassed (turning it off, editing the script, or posting from another location, etc) and thus you need to write your PHP defensively as if its your only line of defense.

Remember, anything client side is easily manipulated.

So are the W3C Schools tutorials really the best way to start? I find it really hard to grasp and when I struggle to do something like refresh an image on a page within a div (not managed to do it) it frustrates me as even an average coder could probably do it with ease, just makes me feel useless.
'

I'm not a teacher, so I can't really tell you what the best way to do it is. A couple of things you should probably try to get right from the start:-

  • A little bit of DB knowledge goes a long way. Normalization is something you'll want to know a bit of. DO NOT USE MYISAM as your MySQL database engine. Personally I'd recommend PostgreSQL but MySQL is fairly popular, so just keep in mind utf8 + InnoDB if you roll that.
  • Use PDO (or maybe MDB2) as your database library. Most of the tutorials on the web will suggest you use mysql_* functions, you shouldn't use them.
  • Read up on transactions, triggers and constraints and utilise them where appopriate.
  • Use prepared statements. Might as well use them with every statement, they should save you from SQL injections.
  • Even though you have prepared statements, validate all your input!
  • Try to use OOP, reading up on MVC isn't a bad start.
  • Even if you don't roll full out MVC, separate your logic from your front end code. Using a template system like SMARTY is a decent way to start.
  • Move onto a popular framework when you're comfortable with what you're doing.
  • Might be a good idea to plan ahead, but at the very least, document as you go. Anything you don't understand right away deserves a comment. :)

Doing the above will probably take you longer, it should remove at least some of the common mistakes. Probably a good idea to read up on why those things are good though.
 
I've just had a quick look at the w3schools.com PHP stuff and it looks like more of a reference than a tutorial. TBH there's already pretty decent reference material at http://www.php.net/ so I'd probably steer clear of secondary sources.

Forget trying to learn all the functions, there are just too many and you won't use the vast majority of them anyway - it's like an amateur writer attempting to become a novelist by reading the dictionary.

Assuming you understand the foundations, (i.e. variables, conditions, loops) the best way of learning is having a problem that you need to solve. If you haven't got one, make one up. Relate it to something you've already got as a hobby so it'll keep your interest, e.g. creating a catalogue of your music collection, building a rankings page for your work 5-a-side league, etc.

Once you have a problem, start with the basics - "what does the application need to display?" Which leads to "What information does it need to store?", "How do people interact with it?", "Who is allowed to interact with it?", etc. This will break down the problem in to smaller more focused issues that can be tackled individually.

Taking the information question as an example, think about what you need to represent - it might be users, products, results, etc. What properties does each of those elements require? Once you have a vague idea, start to research how best to organise and store that data. stackoverflow.com is brilliant for this kind of stuff - it's worth reading all the comments as bad answers are usually be corrected.

Once you know the data you're storing, and the way you want it displayed, then the questions about the bit in between should come fairly naturally, and will lead you automatically to the functions you should be using, e.g. "how do I retrieve rows from the database?", "how do I loop through my data?" etc.

A huge amount of developing (assuming you're trying new stuff regularly) is being good at googling the right questions, and then being able to work out which results seem reliable. Unfortunately the latter is something that only really comes with experience and reading a lot of other peoples code.

Anyway, hope that helps.
 
Back
Top Bottom