Hi people,

I am so interested in learning PHP as it is a powerful language in the web. I know a little bit of PHP so you can say that I've got an intro to PHP at this stage. What I am really struggling the logic of PHP. What would you suggest for me to do or learn as a beginner?

If anyone is out there using this Book Called "PHP Cookbook ", Please do tell me about it. Is it easy to understand from the first attempt reading it? Is it useful?

I saw the book on O'relly site and I think I will get it. So, before I buy the book, I want people using the book to tell me about it please.

Member Avatar for iamthwee

Best way to learn anything it to dive right in.

Create a few projects. You don't even need to buy web hosting...

Just download WAMP or LAMP any you're set to go.

There are a lot of good books out there, I could make you a list. But to save trees and some money, I would suggest you start with this series of tutorials: http://devzone.zend.com/article/627

It's well written and you'll learn the basics fast and write code as you go, which is the best best way to learn. He also has two small projects at the end.

Once you finish that one, pick a project and start coding, googling and asking questions as you go, you'll be amazed how much you'll learn. Some other great free resources include:
http://phpacademy.org/videos/index.php?all
http://www.thenewboston.com/?cat=39&pOpen=tutorial

The best way to learn to code is to code, so go for it :)

As a fresher you will be confuse what to read and from where?
As a starter you can learn below points from Google.
- Refer basic functions like echo, print, exit, die, mail, implode, explode, count.
echo and exit will be useful for debug your output.
- How to submit form in php.
After form submission handle different input fields like check box, radio button, file, text box.
Contact us form is best example.
- Basic string and array operation.check php.net you can find example below function description.
During project coding you need repeatedly string and array usage.
- Now take a database like mysql. Starting from mysql_connect take a look for basic mysql function.
Make a demo page for listing data, add new data, edit data and delete data.
After this much basic info you can play with php.
Whenever you stuck anywhere there is always php.net and Google 'How To' available for you.

All the best..

commented: useful +4
Member Avatar for diafol

I always try to warn anybody new to PHP to beware of the problems that I encountered when I first started.

PHP is easy. Too easy. You code some rubbish, and it works (after a fashion). Before long you're 'coding' complicated stuff with the use of about 10 different built-in functions and a couple of if/elseif/else and switch control structures. Then it hits you.

You're duplicating code all over the place. As your project gets more complicated, you find that you can't scale it and you have to rethink the wiring and start again. Your database needs altering, but this means your data handling routines need to be to be rewritten.

When you look at your code, it's all very messy, mixed up with your html. It's not good.

So, I suggest that you get stuck into creating functions as quickly as possible to avoid duplication of code and then start creating OOP code, using classes. This is something I really struggle with now after a lifetime of 'lazy' procedural coding.

Learn the basics first though:

variables, data types and constants
control structures (if, switch)
arrays
functions
mysql (or whichever DB you're using) functions and data handling
*thorough understanding of (X)HTML and CSS is a must*

After this, you may find using templating engines help you to separate your php from your html. Just a thought.

BTW, I like books. I find them far more relaxing. They are peer-reviewed and are *generally* accurate. Any idiot can write an online tutorial. Having said that, there are some great ones out there.

True, PHP makes you want to rewrite your code all the time.
Writing or using an Active Record thing also really helps IMO, it save you from writing get_this() and edit_this() and remove_this() and get_another_thing(), etcetera, for every database table you create.

Thanks all for passing by and giving me advice.

To vibhadevit, Thanks a lot again. I do agree with you at the point that is what to read since there are heaps and heaps of tutorials. What I want to do at the moment is to get the basics down and master the language. Would that be a good idea to learn PHP and JavaScript at the same time? How secure is PHP? How can you tell the diffs between PHP 5 and 4 and 3? Are they way different?

Truly speaking i haven't used older versions so practically m not aware.
But theoretically php5 is more on object oriented programming like instance, constructor etc.Latest version also offers its own improvements and add-ons.

Some of the php functions are depreciated from php 5.
By referring php.net you will see that difference. example http://in.php.net/manual/en/function.mysql-escape-string.php

Some of google links:

-http://www.dedicatedserverhosting.com/2010/10/20/differences-between-php4-and-php5/
-http://phpguru.biz/blog/find-php-tutorial/what-is-main-difference-between-php4-and-php5/
-http://tycoontalk.freelancer.com/php-forum/78717-differences-between-php4-and-php5.html

JS is one of my favorite.
You can simultaneously check JS form validation
e.g. email validation, password validation, string limit, checkbox-radio button validation.
How to toggle any html data on any event like user select any drop down value and div's content is changes based on selected value.

Have a look with combination of php + js => AJAX.

Thanks. The only thing annoys me is that getting the logic. How do you people get the logic of any programming/scripting language? Especially, with having different syntax.

Logic is the thing which can be improved practice by practice.
There is no such technique to achieve it.
The more you can think and try different way of coding more you have grip over programming.

Member Avatar for diafol

Follow examples. Try to keep your code tight, but allow it be flexible and scalable. Avoid needless loops especially nested ones. Having said that, using arrays could save you a lot of repetitive coding.

One thing I'd suggest is: spend some time learning SQL. The performance gains here can be HUGE. Most of us when we start, write loops that run an SQL statement x times instead of using a JOIN.

Logic can be gained from simple sketches, anything from a flow charts to UML diagrams. See where there may an be overlap of functionality. Try to place common procedures into functions (class methods when/if you progress to OOP).

Separating your code into different files will also help, e.g. config.php to store global variables and constants, functions.php to store common functions.

There are tried and tested stock procedural code snippets out there (e.g. mysql queries and login scripts). Study these.

commented: nice info +8

Hello rotten69

this is my website i write a tutorials for php and other languages ,it's simple to learn
[removed]

:)
What a stupid site. XHTML5 doesn't exist and there isn't a V in "languages". And by the way, why do I need to sign up to access anything? Except for some holiday pictures, apparently.

Member Avatar for diafol

Ditto twiss. It has a certain 90's feel to it though, but not in a good nostalgic way.

@asela - this seems to be a shameful plug of your site, which you cannot access unless you sign up. That's lame.

Dear,
Can you visited [removed]
Can you learn level basic from 1-20 and other lession
Goodluck

Well, I wouldn't recommend that site either. Apart from that it's not English (nor another language I speak)those examples don't make too much sense. Didn't look into the rest of the site.

I always try to warn anybody new to PHP to beware of the problems that I encountered when I first started.

PHP is easy. Too easy. You code some rubbish, and it works (after a fashion). Before long you're 'coding' complicated stuff with the use of about 10 different built-in functions and a couple of if/elseif/else and switch control structures. Then it hits you.

You're duplicating code all over the place. As your project gets more complicated, you find that you can't scale it and you have to rethink the wiring and start again. Your database needs altering, but this means your data handling routines need to be to be rewritten.

When you look at your code, it's all very messy, mixed up with your html. It's not good.

So, I suggest that you get stuck into creating functions as quickly as possible to avoid duplication of code and then start creating OOP code, using classes. This is something I really struggle with now after a lifetime of 'lazy' procedural coding.

Learn the basics first though:

variables, data types and constants
control structures (if, switch)
arrays
functions
mysql (or whichever DB you're using) functions and data handling
*thorough understanding of (X)HTML and CSS is a must*

After this, you may find using templating engines help you to separate your php from your html. Just a thought.

BTW, I like books. I find them far more relaxing. They are peer-reviewed and are *generally* accurate. Any idiot can write an online tutorial. Having said that, there are some great ones out there.

Well said.
I would add that w3Schools is good start though Vikram's PHP 101 is still my best out there ;)

Thanks all for the comments and wonderful advice. All are well-appreciated.

@snips,, I am not after an instruction on how to install PHP server. I think the title is clearer. But, anyway, thanks for the link. Others might benefit from it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.