Learning PHP

Associate
Joined
13 May 2004
Posts
1,491
Location
Wales, Wrexham
I have tried to teach myself the basics of php about four or five times now and always give up after i've learned the very basic code to set up a php document, setting variables, if statements and so on - then always hit a wall, not knowing where to go next as far as being self taught is concerned.

I want, ultimately to write my own CMS for a website, whether it is very basic or not, it wont matter - i just dont know where to look, what aspect of the language to teach myself next

Sure i could find a script through google, but then its just guesswork as to what everything does, some is logical, other bits arent - i'd like to learn the general process, if you know what i mean?

Any advice here? I feel i can make a serious committment to the language if i actually achieve something worthwhile, i want to make scripting a profession later on in life, just need a few foot holds!

Thanks in advance, and if anyone can suggest any simple PHP projects for me to set my mind to before the CMS, that would be awesome!

Oli
 
I completely self taught myself PHP. Everyone always raves about online guides (not just for PHP), but I can honestly say I've never read one. I guess it depends how you work/learn.

Usually I just Google problems - ie. how to do something specific rather than reading 1 big guide, then I copy code and adapt/change it. Eventually you remember the code!

For a CMS you'll need to teach yourself MySQL. Sessions will be useful too.

I'd just "do" it and practice. And if you don't know how to do something then Google how to do that specifically (ie. create a database and a connection).

I probably shouldn't give any more advice as I'm a bad coder - everything I do is probably ugly as sin and just in a bodged way, with if statements everywhere and no comments. But as far as I'm concerned for personal projects, if it works then it works! :p
 
I would love to be able to code but for the life of me I can just not seem to learn via guides or books.

I have always found it easier to learn when someone actually shows me what to do.
 
I learnt php doing an ecommerce project. Like you I'd read reference books but until you actually come to apply the knowledge to something specific it can all seem a bit confusing.

If I was starting out again, I'd definitely reccomend setting up an online store using something like paypal as your payment system. A cart, product and category relationships and their displays, email address collections, newsletter systems, payment gateways, IPNs, the whole shebang associated with something like that will really give you a wide range of tasks to use php and MySQL for.
 
+1 rghjones

Ive never looked at a book, I just did what I could and googled what I couldnt.
Code is probably slightly bloated but not the point of it slowing down a website, just people being picky to save an extra few characters which may have an effect if the website was being used by thousands at once.

I couldnt understand PHP for a long time and even when a friend did something for me, I just couldnt get my head round it. But then all of a sudden it clicked and everytime I do a PHP project I learn much more.
I took a 2 month job 18 months ago which was building a bespoke ecommerce website from scratch. I had literally no clue at the start but learned very quickly and now I'd say I am good with PHP/MySQL as I have built my own CMS, eCommerce website and a few other things.

Best way I found to learn, was to do!
 
as has been said really, just start doing something with php and you'll quickly learn. e.g. start by just getting php to display your name, then get it to do a bit of math and display it, then a bit of math and depending on what the number comes as display either hello or goodbye. then get it also to display the date but in a format of your choice such as 01-12-08 or 1-12-2008 etc.

just start really small and think of something small you could add to it. i'm forever making something with php, often something very very similiar to what i have already done, but it's great as i come across a new problem everytime, learn the solution then move on to next thing, find a problem, learn more.

make sure you keep the code you make as it's always fun to look back and see how silly you were at doing things.
 
Yeah start small. This will help you learn the basics. Set yourself simple projects, then add to them.

I used the Wrox Professional PHP4 book (guess it should be 5 now!) and the resources at php.net.

I really wouldn't start by writing a CMS. There's load of them out there, for free that will do a good enough job for most purposes.
 
I enjoy messing about with PHP, but I am not a crack programmer.
Books are good but humping them round all the time is a PITA.

Best resource I use now is PHP.net - has everything you want :)
 
I have a few PHP books but to be honest I've not read much of them, I teach myself by doing wee projects and experimenting, many books I find don't address the things I specifically need, and it takes ages to find anything amongst it.

I use PHP.net online documentation a lot, has everything you need and there are usually people posting nice scripts in the comments. :)
 
Well I started to fiddle today with PHP, it sort of makes sense, so far I have just been messing with declaring a couple of variables, and then adding them, subtracting them etc.
 
First thing I'd suggest is that you forget about it as "the way to make a web page" and concentrate on it being a programming language.

It has all of the normal programming structures (variables, functions, objects, program flow control) and has a lot of functions and objects already predefined (connecting to a database, handling files of various types (e.g. CSV files)...

Once you get away from the idea that the purpose of it is to create a web page, it becomes much easier to visualise how to use it to develop an application.
 
As a professional software developer my view is pretty much coming from the opposite end of the spectrum. If you can't do learning by book then its pointless for me to advocate it, but you really need to widen your knowledge more than just googling how to overcome a_specific_task.

Code has knockon effcts, security implications etc that makes it a really good idea to learn on a broader level, to learn about advised methods for design/coding style, and have your awareness raised of where security implications are apparent.

php.net will tell you how to use a method or property, but it will not teach you how to (properly) program. A noobie guide book is a great way to learn something. The best book I ever read is called "PHP 5 Objects, Patterns, and Practice" - but it is not a novice book that's going to help you get started.
 
Thank you everyone for your advice thus far, i decided to purchase a couple of books on the subject, and i've settled with "Beginning PHP5, Apache, and
MySQL® Web Development"

It has so far led me through what the basics of the different abilities of PHP are, what kinds of code to use, where and when etc.

The best thing, in my opinion about the book is it actually has the 'small projects' there for you to do, although the code is actually there it helps to see what you have just read / learned in context.

So far i'm about 100 pages in, and its explained different ways to call lists, defining, including, basic functions.

The only thing i find hard at the moment, is remembering all of it... i am trying to go back day by day and write what i learned the previous day from memory, which i am managing okay, but certain things i find very hard to remember, lots of which are to do with the likes of $_SESSION and so on, i'm sure like any language (programming or lingual) it will get easier with time, i just feel reluctant to continue to the next part of the book before i know this part 'off by heart'

No idea what other peoples views are on that!

The small project i've set myself, is to be able to create some kind of image upload / view program with a basic rating system, i havent learned enough to do it yet but i remain hopeful!
 
OP doesn't make reference to their programming experience. Slightly off topic but.... y'kno, just my two pennies......

I've done a fair bit of programming [.NET, PHP, Java, Pascal, C/C++... etc]. PHP isn't difficult but the amount of times I see over-engineered scripts (in any language) is amazing. IMO, when you are developing ANY data-driven system, take one step back from your programming and PLAN the data structures behind it. PLAN PLAN AND PLAN liked you have never PLANNED before!

I will give you one example.

Table A
Col 1 PK
Col 2 FK TABLE B - COL 1
Col 3
Col 4

Table B
Col 1 PK
Col 2
Col 3


Now. I have lost count of the times where I have seen programming along these lines :

1. select items from table a
2. loop through items from table a
-> retrieve item from table b where col1 = a.col2
3. print results to page.

Not only is this poor design and programming but it results in slow page loading and increased loads (critical if your site is busy).

This of course, could be simplified to

1. select * from tblA, tblB where tblA.col2 = tblB.col1 (with associated join if necessary)
2. print to screen

Remember where to use your databases inbuilt functionality. Use plenty of views, if it helps you. This will also help with maintaining your code as you can edit the SQL behind the view without even touching your PHP. Databases are good at processing large amounts of data. PHP webpages are not. Just remember that and your life will be a lot simpler. Do not bother developing any data-driven system without having a good understanding [nb. not 'expert knowledge'] of SQL and, if possible, one of the major DBMS [Oracle, SQL Server or most likely in this case MySQL].

OP also makes reference to searching for scripts on google. Sure, using these scripts may add up to guesswork. BUT, if you are taking the team to read through these and attempting to understand what they do, you will learn a LOT. If you are unsure as to what a particular function does - google it and learn a bit more. It's an iterative process. You will never stop learning.
 
Set yourself a small, simple project to begin with and work your way up. Don't try to bite off more than you can chew – a full-on CMS is out of your depth at the moment.
 
I chose PHP to implement my final year project for uni, I'm beginning to wish I hadn't as I am finding it hard to know where to begin. I have experience with procedural PHP and a lot more with Java. I have learnt about most of the OOP features in PHP 5 now but there is so much conflicting information about structuring a web app. I understand that shoul split the presentation (XHTML/CSS) from the application logic and data, I have done this in Java on smaller projects but with PHP it seems a mess. I am assuming it's due to legacy of the language, even with PHP 5 there are still plenty of people doing it the old way.

Any pointers or resources people have would be helpful.
 
I chose PHP to implement my final year project for uni, I'm beginning to wish I hadn't as I am finding it hard to know where to begin. I have experience with procedural PHP and a lot more with Java. I have learnt about most of the OOP features in PHP 5 now but there is so much conflicting information about structuring a web app. I understand that shoul split the presentation (XHTML/CSS) from the application logic and data, I have done this in Java on smaller projects but with PHP it seems a mess. I am assuming it's due to legacy of the language, even with PHP 5 there are still plenty of people doing it the old way.

Any pointers or resources people have would be helpful.

I would suggest using a framework, but this probably isn't an option if you're doing a final year project. It might still be helpful to look at a few to see how they do it, though.

A couple of good frameworks are Kohana and Zend (possibly a little too complex for your needs), or Picora if you want something really lightweight.
 
i would love to find someonline sites, but they all seems to "skip" sections wherei suddenly think we missed something...
 
http://www.killerphp.com/videos/ - may be a good place to start.

Imo, you can read (or watch in this case :)) about programming all you want, you start to understand and remember things when you actually use - for me, thats when ideas start to sink in.

When you start to understand it a bit more, you could take apart a bigger application to see how it works. I recently found a free php based ecommerce solution called prestashop.

You can download the source and have a look at all the classes (All the code is in classes) they have used and how it all works basically (btw, the image gallery on the product detail page is amazing imo!).
 
Back
Top Bottom