Jump to content

best way to learn php/mysql?


Snap40

Recommended Posts

First off Hi to all of you;)

 

I have started taking various tutorials around the web.I am Starting to understand "in general" a few things.But just having something echo back to me what i wrote on the code seems to still not help me understand how it works on an actual site(i hope this makes sense to someone).

Since allot of you are experienced coders i thought i would ask here,what would you consider to be the best way (or place) to learn php and mysql?IE:books or video tutorials or tutorials like the ones on this site.Or even an online university?

 

Thanks in advance

Snap40

Link to comment
Share on other sites

Tutorials are intended to teach one aspect of something. You would need to find a comprehensive list of tutorials to even come close to being exposed to the amount of information and with the organization that would exist in a basic book on the subject. For example, the w3schools.com PHP tutorial briefly covers the basics, and even has a short example or two in each section, but a basic book will typically build up examples that actually do something more than echo that something worked. I recommend visiting your local book store, browsing through the books that cover the subject you are interested in, picking one that matches your level of understanding, and reading through it (multiple times as necessary.)

Link to comment
Share on other sites

All of them. Seriously, just assault your senses and emerge yourself within the language. You will LOVE php, though it will be a love-hate relationship at first. When you finally start seeing the big picture, it's incredible.

 

This is no doubt true for other powerful programming languages, but I started on html and css so this was a BIG evoluionary step in my programming career. The power is...wow..

 

Anyway, I suggest you absolutely download and install wamp as soon as you can so you can test php code locally. Get notepad++ for coding, maybe move onto something more elaborate later (I never did).

 

Then read, watch and observe *while* you have your local server in front of you. Practice, practice, practice, it's the best way.

 

Once you develop a firm understanding for the syntax, look up best practices and shorthand, then move onto security. Don't worry about making everything perfect, just develop your current scripts as you go.

 

Learn to build functions and simple classes and finally move onto oop-based techniques.

 

My best advice though is to get wamp (if you have windows) and start practicing on your machine while you read from books and/or watch vids.

 

When you think you're ready, delve into a small! php project, like on rentacoder and see where it takes you. I learned most of what I know through *necessity* by accepting things I could only just grasp and learning as I went along.

 

Really hope that helps.

Link to comment
Share on other sites

Start with the manual. Make sure you've understand the syntax and make sure you know the features PHP has. Make sure you're at least decent with math (not just 1+1=2 shit, I mean real math). That will help you a lot, and the way you need to think when doing math coincides with the way you need to think when programming.

 

A good exercise might be to try to implement some of the functions provided in PHP's library. Try for instance to implement explode without using any PHP built-in function. What does it mean to split a string into an array at a particular delimiter? Can you explain it in English (or whatever natural language you're most proficient in)? How about strlen? What does it mean to get the length of a string? Can you explain how you would do that outside the context of programming? If you can explain it using words, you can explain it to the computer with a programming language assuming you know the syntax.

 

Programming is essentially problem solving, i.e. how do you most efficiently get a computer to perform a particular task. The kind of programming I described is called imperative programming. It works sort of like a recipe for when you're cooking. You are explaining the computer what to do with a particular input and then produce a particular type of output. Another programming paradigm is called functional programming, which I would encourage you to look into some time. With imperative programming you explain what to do, but with functional programming you explain what things are.

 

When you are able to do problem solving and decompose a large problem into smaller subsets of problems you will want to learn how to organize your code in a practical manner. You will want to look into object oriented programming (OOP) and object oriented design (OOD). You will want to look into methodological topics such as what e.g. agile programming is, what TDD (test driven development) and unit testing is.

 

You would probably be inclined to read tutorials like "how to create a membership system", "how to write a CAPTCHA" and so on. Practical tutorials that end with a very clear and quantifiable result. I would not recommend this. You don't want to know how to create a membership system. That skill in itself is entirely useless. You will want to know what a membership system consists of, and you will find that those individual steps are fairly manageable.

 

Starting at a lower abstraction level has several benefits. It will train you to think about how the algorithms you implement work and it will train you to think like a programmer. Of course you will not want to use your own explode() implementation in a real program. Usually it's a waste of time reimplementing things. You will hear people say "don't reinvent the wheel", and that is true, mostly anyway. In any real application it's true, but it's not true in a learning environment.

 

Using this approach it will probably take some time before you create anything meaningful, but in the long run you'll benefit from it. I've been know to say that "PHP is too easy", and I believe this to be true. It's too easy for anyone to start right off the bat and create something concrete. The problem is just that these people's codes are fundamentally flawed. They use bad practice, their code is highly inefficient, not at all maintainable and full of bugs and security vulnerabilities. Sure, they produced something, but the fact remains that it plain simply sucks. Programming done right is not easy, and anyone who tells you it is is either lying or not a good programmer.

 

Don't ever think you're good enough. Don't stop at a plateau. Make sure you keep learning, keep reading, keep practicing. There is someone better than you. Strive to be better than them, strive to be the best. Remember that finishing something faster does not necessarily mean it's better.

Link to comment
Share on other sites

hi thanks for the quick answers.I have xampp on and working and have been using it for the tutorials,i have like 4 different test folders in it  :D. A book is maybe a good idea although i like the hands on stuff better and i guess im a bit impatient as well hehe.

I have also paid for a couple tutorial videos as well and enjoyed them and learned as well.I'm not sure maybe trying to create my own project and learning from my mistakes could be a route to try too.

 

PS:thanks Daniel i was in the middle of writing this when you posted.Some good ideas i will try thanks!

Link to comment
Share on other sites

Impatient and programming don't go together. Getting computers to do what you want is very detail orientated and requires an amount of reading to figure out how use the pieces present in any programming language to get from point-A (a statement of your problem) to point-B (a working solution) without wasting a lot of time and effort trying to get there.

Link to comment
Share on other sites

Just try to create something useful for yourself if you think you got a good grasp on the basics.

 

Try extracting the artists names from your music collection, or mimic your filebrowsers behaviour, create some script able to do some tedious task like filtering down the RSS feed of your favorite site down to only the results you find interesting. I've never really lacked a 'target objective' of something I wanted to code. Granted I use PHP for some silly things like moving files or slicing up images where I really should instead be using shell scripting or a desktop based programming language for.. but little projects tend to be a very useful learning experience. It's easier to concentrate on something when you got a purpose for it as well.

Link to comment
Share on other sites

Grab an example, play around with it and experiment

 

I remember the first time i learnt how to update a database, i was jumping around. Databases used to scare me - until i found out how simple it really is.

 

Finally : Program from the heart - its more fun

 

 

Link to comment
Share on other sites

Grab an example, play around with it and experiment

 

Unless you somehow can ascertain the quality of that example, I would be extremely cautious with that approach. Worst case you end up picking up a lot of bad habits and bad practices. See the PHP Help forum for proof.

Link to comment
Share on other sites

Grab an example, play around with it and experiment

 

Unless you somehow can ascertain the quality of that example, I would be extremely cautious with that approach. Worst case you end up picking up a lot of bad habits and bad practices. See the PHP Help forum for proof.

 

I love php and mysql manuals now, but i couldn't understand them when i started.

 

 

Link to comment
Share on other sites

Pick a simple project such as a blog with a login system to start off with. Learn enough PHP & MySQL to build it. Then post your code here and let others tell you what you could have done better. Go back and make it better. Then post again. Then start a new project. The #1 thing is to keep looking for ways to improve your code. There's nothing better than figuring out how to do something in three lines of code, where it used to take you fifty!

Link to comment
Share on other sites

Ditto to what waynewex said.  I've been programming for close to 15 years now and I think I can accurately outline the learning hurdles you need to overcome:

 

When initially learning you are presented with programming concepts in general and a specific programming language.  Programming concepts are things like functions, arguments, return values, pass by value, pass by reference, memory management, references, pointers (maybe not so much any more), algorithms, and then finally more advanced topics like object oriented programming, abstract data types, advanced algorithms, etc.  It will take some time before you can effectively use these concepts to solve a particular problem; you actually have to train your brain to think a little differently about things.

 

A specific programming language is all about how it implements those general concepts.  An example would be all PHP programs start with <?php or PHP functions begin with function theName() { or that PHP uses references rather than pointers.  Really it's about the syntax, which is what you have to type, where you have to type it, and what it has to look like.

 

The beautiful thing about programming is the general concepts do not change from language to language, only the syntax.  A real programmer can easily learn new languages and write the same programs in many languages because all that changes from language to language is syntax (and a few other silly things sometimes).  I've known a few people that could program one language but were unable (or maybe just unwilling) to learn a new language, saying it was "too difficult" to get around the different syntax.  IMO they're not really programmers.

 

As a beginner the general concepts you need to be familiar with are: variables, functions, loops, conditional statements, input and output.  Once you know how those all work in PHP, start writing small programs.  After it's finished, think about how you could have written it differently.  Ask yourself, "What design decisions did I make in this program that made programming it harder than it needed to be?"  Ask yourself if the program is easy to maintain.  Do you think you could open the file in 6 months and follow your own code?  Then actually open the file 6 months later and look at your old program and critique it then.

 

As I said I've been doing this for a while.  Once you overcome the hurdle of learning about general concepts, the rest is just how a specific language accomplishes a specific task.  The only real way to get better is to write lots of programs and constantly try to make them better!

Link to comment
Share on other sites

Best way to learn is to just do it! The more you play with it the more you'll learn. I think I'm still a newbie but when I'm finished with a project I look back and sometimes wonder how the heck I did it.

 

I guarantee you, in half a year you'll think what you did sucks. If you don't something is wrong and you haven't learned anything in the mean time.

Link to comment
Share on other sites

Best way to learn is to just do it! The more you play with it the more you'll learn. I think I'm still a newbie but when I'm finished with a project I look back and sometimes wonder how the heck I did it.

 

I guarantee you, in half a year you'll think what you did sucks. If you don't something is wrong and you haven't learned anything in the mean time.

 

I'm pretty sure in a half of year I'll probably think what I did sucks. I'm still learning. When I look at my codes I know what I did. I meant to say something more along the lines of I'm amazed I've come this far from just reading books and getting help here.

Link to comment
Share on other sites

Lol, Daniel0; your post about doing stuff just for the sake of it got me thinking...so I had a go at making an explode function like you suggested.

 

:D

 

<?php
class explode
{
	var $string, $buffer = array();

	function __construct()
	{
		return true;
	}
	function explode($delimiter, $string)
	{
		$this->string = $string;

		$string = array();

		foreach($this->tokenise() as $key => $value)
		{
			if($value == $delimiter)
			{
				array_push($string, implode($this->buffer));
				$this->buffer = array();
			}
			else
			{
				array_push($this->buffer, $value);
			}
		}

		return array_merge($string, array(implode($this->buffer)));
	}
	function tokenise()
	{
		$array = array();

		for($i = 0; $i < strlen($this->string); $i++)
		{
			array_push($array, substr($this->string, $i, 1));
		}

		return $array;
	}
}

$explode = new explode;
$string = 'hello world ';

print_r($explode->explode(' ', $string));
?>

Link to comment
Share on other sites

Best way to learn is to just do it! The more you play with it the more you'll learn. I think I'm still a newbie but when I'm finished with a project I look back and sometimes wonder how the heck I did it.

 

I guarantee you, in half a year you'll think what you did sucks. If you don't something is wrong and you haven't learned anything in the mean time.

 

I'm pretty sure in a half of year I'll probably think what I did sucks. I'm still learning. When I look at my codes I know what I did. I meant to say something more along the lines of I'm amazed I've come this far from just reading books and getting help here.

 

I've been coding PHP for I think around 3 years now, and I still look back at things sometimes and I'm like "Wtf?!"

 

 

 

 

 

jxrd, I have a question...  Why did you wrap it in a class?

 

 

 

I'm procrastinating what I should be doing (x.x), so I decided to give it a go:

 

//array explode ( string $delimiter , string $string [, int $limit ] )
//I don't feel like implementing $limit
//Also, I would use better names than $d and $s if I were going to use this for real lol.
function splode($d, $s) {
$len = strlen($s);
$offset = 0;
$out = array();
//while(($place = strpos($s, $d, $offset)) !== false) {
while($offset < $len && ($place = strpos($s, $d, $offset)) !== false) {
	$out[] = substr($s, $offset, $place-$offset);
	$offset = $place+1;
}
//The place = blah !== false will not get the last match...
if($offset < $len) {
	$out[] = substr($s, $offset, $len-$offset);
}
return $out;
}
print_r(explode(' ', 'This is a string with spaces!'));
print_r(splode(' ', 'This is a string with spaces!'));

 

 

When ever I first got into C++, I didn't know that the std::string class had a method designed for tokenizing a string, so I once recreating explode() in C++.  It was essentially the same as this haha.

Link to comment
Share on other sites

jxrd, I have a question...  Why did you wrap it in a class?

Idk, I needed to use two functions...thought it would be appropriate.

 

I guess I'm just not as resourceful as you :P

 

But...I bet you can't do strlen() !!!!!

 

<?php
function str_len($str)
{
	$str = preg_split('/./', $str);

	return count($str) - 1;
}

echo str_len('7 chars');
?>

Link to comment
Share on other sites

Heh... you cheated and used built-in functions. Here you go with a with an explode() implementation that doesn't use any of PHP's built-in functions whatsoever.

 

function myStrlen($string)
{
for ($length = 0; isset($string[$length]); $length++) {}

return $length;
}

function myExplode($delimiter, $string, $limit = null)
{
$parts = array();

for ($i = 0, $j = 0, $length = myStrlen($string); $i < $length; $i++) {
	if ($string[$i] == $delimiter && ($limit === null || $limit > $j+1)) {
		$j++;
		continue;
	}

	if (!isset($parts[$j])) {
		$parts[$j] = $string[$i];
	}
	else {
		$parts[$j] .= $string[$i];
	}
}

return $parts;
}

Link to comment
Share on other sites

isset() is a language construct, so I still win :P

 

Here you have a few others:

function myImplode($glue, array $pieces)
{
$string = '';
$maxIndex = myStrlen($pieces)-1; // myStrlen() will work for arrays because of the way it's written
foreach ($pieces as $i => $piece) {
	$string .= $piece;

	if ($i != $maxIndex) {
		$string .= $glue;
	}
}

return $string;
}

function myStrpos($haystack, $needle, $offset = 0)
{
for ($i = $offset, $length = myStrlen($haystack); $i < $length; $i++) {
	if ($haystack[$i] == $needle) {
		return $i;
	}
}

return false;
}

function myStrrpos($haystack, $needle, $offset = 0)
{
for ($i = myStrlen($haystack) - 1 - $offset; $i >= 0; $i--) {
	if ($haystack[$i] == $needle) {
		return $i;
	}
}

return false;
}

Link to comment
Share on other sites

Lol

 

How would you do foreach()?

 

I tried it in C++ the other day...didn't do too well. C++ arrays confuse me...with their vectors and stuff.

 

My initial thoughts would be var_export()...but obviously that's a built in function.

 

Appologies for off-topic-ness btw :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.