58 Comments
- sxtxixtxcxh, on 10/12/2007, -1/+27Parse error: parse error, unexpected T_VARIABLE in http://digg.com/programming/PHP_Programming_Basics#c4803226 on line 3
- vh1`, on 10/12/2007, -9/+35$salary = "3000";
$bonus = "1000";
$total_salary = $salary + bonus;
...
sure, make them strings instead of integers. makes sense - sroberson, on 10/12/2007, -3/+22Yeah, we should only use Flash. Screw search engines!
- polymorphist, on 10/12/2007, -1/+12"Why do people go for MySQL (read it as "Your SQL") instead of the greate one
PostgreSQL
I just dont get it."
Because most of the time the better solution isn't the most popular one. - MoneyShot, on 10/12/2007, -1/+10Why's vh1 being dugg down? He makes a valid point. If you're going to post a tutorial, you'd better make sure you understand the language yourself. Also, the fact that this bit of code actually works is an indication of one of problems of a weak typed language.
- ehask, on 10/12/2007, -1/+9Damn you guys are cruel........ Never bash someone for free information I learned all the languages I program in on my own from articles like this. I was a Systems/Network guy Cisco certified and now program for a living for a large E-tailer
Thanks for the article I hope it helps someone find a passion for code. - biff198, on 10/12/2007, -2/+10Ugh... It's like reading "Elmo learns his PHPs"...
- Asianne, on 10/12/2007, -4/+12Very nice guide, and one I hope will be useful to many. Although I've learned php and other forms of code/script/programming by just doing it myself, it's a good link to pass on to others who bug me during my code time with simple PHP questions :)
- RationalAntaxia, on 10/12/2007, -5/+12go to www.w3schools.com and learn there.
it puts this one to shame! - krinthekuz, on 09/16/2008, -0/+7php string concatenation uses the . operator
$first = 'you smell';
$second = ' like poo';
$both = $first.$second;
the value of $both is 'you smell like poo'.
you can also do
$thestring = 'you smell';
$thestring .= ' like poo';
the value of $thestring is now 'you smell like poo'. - jpirkey, on 10/12/2007, -1/+8This tutorial is ridiculous. It teaches bad programming practices. When does "3000" + "1000" in any other language besides scripting languages equal "4000". They should teach good programming practices, so that the person can learn on a fairly easy language, then apply them to more complex languages. I learned a few different programming languages in school, but I was taught how to program (problem solving using the tool of a programming language). There are many programming languages out there. To teach that string 3000 plus string 1000 is string 4000 explains exactly why there are so many mediocre programmers out there.
Furthermore another example that irks me from people that claim to know php, is the:
echo "Hi" . $name .", " . $question;
When is it necessary to concatenate output. The proper statement should have been:
echo 'Hi ', $name, ', ', $question;
- or even more readable -
echo "Hi $name, $question"; or
There is no need to make the 3 concatenation calls to produce the output.
Anyway, enough ranting. Article gets 2 thumbs down from me. - MoneyShot, on 10/12/2007, -1/+7Yeah Postgres is "better" by most definitions of the term. But it also has bigger learning curve. 90% of the MySQL DB's I see don't even use foreign keys, so it's not like these people would gain much by moving to a more ACID compliant RDBMS.
- SuperSloth, on 10/12/2007, -1/+7It's a problem because it's not clear if "3000" + "1000" should be "4000" or "30001000". Addition is suddenly an ambiguous operator.
PHP gets around that by using a different operator for concatenate. - ColdForged, on 10/12/2007, -0/+6Perhaps instead of critiquing, write your own? I'm not being pithy, I'm serious. If you have more knowledge than someone, your abilities would be better used teaching others than simply sniping tutorials :). Of course, it's also far easier to snipe than to create a cogent, informative article.
I put my own money where my mouth was when I wrote my own PHP primer -- I'm no expert -- just to try to relieve the constant amount of questions I got in my WordPress installation: http://www.coldforged.org/archives/2006/11/03/php-primer-and-tutorial-part-1/ . I'm sure it's not perfect either, but if it means that someone who had no knowledge of PHP has a bit more, it can't necessarily be a bad thing. Moderately spammy and I'm sure I'll be dugg down, but I'm trying to make a point. Just a thought. You're welcome to critique mine as well ;). - twodimes, on 10/12/2007, -0/+5Online guides are great, but a few good books are a better way to get started with a new language in my opinion. My personal favorites from this list are:
http://top-books.org/php (top 50 php books)
#1 PHP and MySQL Web Development (3rd Edition) (Developer's Library)
#9 PHP 5 Objects, Patterns, and Practice
#24 PHP in a Nutshell (In a Nutshell (O'Reilly)) - brockb, on 10/12/2007, -1/+5I picked up PHP years ago through the 1st edition of Sam's "PHP and MySQL Development". It was great for picking up the "basics" but it also taught me a lot of bad habits too. I was thumbing through the 3rd edition the other day and it is much better.
- Trenton, on 10/12/2007, -0/+4Although for an amatuer, this works out very nicely. It's great for the people that have almost no knowlege of php.
w3schools is great, and I love it. - ElMoselYEE, on 10/12/2007, -0/+3quoted by polymorphis
"Because most of the time the better solution isn't the most popular one."
i.e. Internet Explorer - haveacigar, on 10/12/2007, -0/+3What? no hello world? Sacrilege
- rclay, on 10/12/2007, -2/+5Postgres wins on features. MySQL wins on support, ease-of-use, speed, and existing skill base.
- sketchydave, on 10/12/2007, -0/+3Agreed. I have the 3rd edition literally on my desk right now and its a very practical book. Unit I: Using PHP, Unit II. Using MySQL, Unit III. E-Commerce and Security, Unit IV. Advanced PHP Techniques, Unit V. Building Practical PHP and MySQL Projects. The nice thing is its one of the few books that assume you know a thing or two about programming and minimizes the hand holding and gets you going quickly.
- CharAznable, on 10/12/2007, -0/+2Terrible tutorial. Anyone writing a coding tutorial should, at the very least, actually try to run the code samples. Even if it's just
echo "hello world";
You never know when typos will bite your ass. - vh1`, on 10/12/2007, -0/+2or even
echo "Hi {$name}, {$question}";
to distinguish between what is a variable and what isn't more easily, without using all the concatenations
this article kind of exemplifies the whole "teach a man to fish ... " saying - klezmer41, on 10/12/2007, -0/+2Holy crap that's a crappy introduction to PHP. There are lots of great resources out there but if you have to pick a couple, start where I started:
http://www.rci.rutgers.edu/~jfulton/php1/index.html
Ignore all the infrastructure stuff in that tutorial, however the discussion about code is short and he gets into MySQL pretty quick. The first thing you should do is create your development environment on your system. I personally use XAMPP on Windows which gives you Apache, PHP, MySQL, and more. There are other options but this is quick and dirty. One thing to note is that Apache conflicts with Skype on my system. I just need to make sure to start XAMPP before I start Skype.
http://www.apachefriends.org/en/xampp.html
Once you have your development environment set up and some working code, then pick up some books and read through www.w3schools.com
You've also got friends on Freenode (IRC server) to help you through it. - transeunte, on 10/12/2007, -1/+3@MoneyShot
"Also, the fact that this bit of code actually works is an indication of one of problems of a weak typed language."
How is that a problem? I fail to see how flexibility translates to inconvenience. If anything. this is an indication that sometimes it is actually nice to have a weak typed language as an option. - iamthewinnar, on 10/12/2007, -0/+2Dugg because I'm to lazy to bookmark the link above.
- Ghoul, on 10/12/2007, -0/+2@jpirkey
I disagree with you on concatenation. Perhaps it is a little less readable, but if you're familiar with the language, it's not difficult. I've never seen commas used for concatenation in PHP, but to me it makes it less readable (especially when there are commas within the text of the concatenations). I'm not sure if that was intentional. Many syntax highlighters also don't highlight variables placed within double quoted strings, making them harder to spot.
Secondly, I prefer to control the output whenever possible. I don't want PHP scanning my strings for variables so it can interpolate them because 99% of the time that is not what I intended. Double quotes require that I escape more characters, and in some cases that can decrease readability.
Also, single quotes and concatenation are faster than double quotes and interpolation, at least from my own tests and from what I've gathered on the Internet. Granted, unless you're putting out megabytes upon megabytes of data using a lot of variables, it's not going to matter, but it's the theory that counts, right?
Anyway, I think we all agree that this tutorial is rubbish. Concatenation on double quoted strings? What's the point? - MeatBiProduct, on 10/12/2007, -0/+2We still have compilers for windows so it really doesn't matter.
- krinthekuz, on 09/16/2008, -0/+2@moneyshot
shrug, if i recall fk support in mysql4 was slightly buggy, and many have not upgraded to mysql5. additionally, the main benefits of using fks (like cascading) requires (in mysql4) that you use innodb, whereas most apps use myisam.
look at the big apps where mysql5 is or was quite buggy in the last year... phpbb, phpmyadmin, mythtv, drupal, joomla, and these are only the bugs that i've encountered in my personal experience. i wish i could mention wordpress, but i never tested it so i can't say from personal experience. - emehrkay, on 10/12/2007, -1/+2It is bad practice to have a integer declared as a string. what if the developer wanted to compare the string later on with the triple equal operator? (===) They wouldn't be able to. There is absolutely no reason that those numbers should be in string format. The only thing that I can come up with is that the writer of the article skipped over it, or just flat out don't know about datatypes.
- CraigJ, on 10/12/2007, -1/+2@MoneyShot. Strongly typed languages have there place, but frankly, when I'm developing Web apps I don't necessarily want to worry about that. The danger is that you need to understand how the types are cast. If you don't understand the types then you could end up with problems, but I leverage the weakly typed aspect of PHP all the time.
I have found this book to be a really very good reference and guide: http://www.amazon.com/PHP-MySQL-Web-Development-Second/dp/067232525X - thetanbark, on 10/12/2007, -1/+2These guides suggest Apache 2.x and PHP 5.2.0. I would highly suggest going with Apache 2.2.4 and PHP 5.2.0. The catch is you should use php5apache2_2.dll instead of php5apache2.dll when assigning a PHP module if using 2.2.x.
ApacheLounge also has a quick and dirty guide to getting Apache/PHP running on Windows and is a little more friendly for future upgrading: http://www.apachelounge.com/forum/viewtopic.php?t=570 - snapple, on 10/12/2007, -0/+1I have made an mmorpg in php before so I can safely say that this was a very uninformative article. I taught myself php through articles like but much better than this one. I understand that this is only the basics of php but I believe this article should link other articles that go into more detail. Obviously using echo and variables are very important, but those tools alone are pointless. It's like having a hammer and a few boards, but no nails to combine them. I know there are many better articles out there on the Internet.
- iNoles, on 10/12/2007, -0/+1 exit; nothing else, it need move along to another things
- jpirkey, on 10/12/2007, -0/+1@Ghoul
echo is a language construct and therefore does not follow the rules of a traditional function. It is much faster for php to echo out with the "," there than to do 3 concat operations (whether with single or double quotes) to create the string, then send that out to the browser. The "," is not a concatenation operator, it is simply a way to separate the arguments to echo.
I don't disagree with your concern with with syntax highlighters. I use Zend Studio IDE for my development and it does do the highlighting properly, on top of that my html is in different files than my classes, and driver files since I use templating. It is rarely an issue for me. Good point none-the-less. - thesixthdesign, on 10/12/2007, -0/+1The PHP in the tutorial is the most extremely extremely simply PHP which will honestly probably not give you any use in life.
IMHO. - inactive, on 10/12/2007, -0/+1It looks like he fixed it.
- russellnation, on 10/12/2007, -0/+1It was really easy for me to install and learn to use with MySQL. very nice, even though i use windows, also ubuntu, havent tried it on my powermac yet though
- MeatBiProduct, on 10/12/2007, -0/+1actually PHP uses polymorphic variables so
$MY_VAR='3000';
$MY_VAR2=3000;
$MY_VAR==$MY_VAR2 (is true).
if you want to combine the strings then you don't use math.
$MY_VAR='3000';
$MY_VAR2=3000;
$MY_NEW_VAR=$MY_VAR . $MY_VAR2;
30003000 is the result
rather than $MY_NEW_VAR=$MY_VAR + $MY_VAR2
which produces 6000 - tempusrob, on 10/12/2007, -0/+1@ColdForged: "Perhaps instead of critiquing, write your own?"
Or, instead of writing Yet Another PHP Tutorial, point people to the official docs instead ... since all the basic crap is covered there anyway. - nucleardonkey, on 10/12/2007, -0/+0Not good; just looking through the installing on "windows" [sic] for starters then it hacks around with the directory structure (not necessary and will cause confusion later on), says to put php.ini in the Windows system directory (bad) and to turn register_globals on (no, don't even think about doing that). The PHP manual's installation and getting started chapters are better than this.
- jinglee, on 10/12/2007, -0/+0so many people interested in PHP basics, and you want me to believe that this is not Paid Spam?
- glomph, on 10/12/2007, -0/+0sorry
its to
http://www.newgrounds.com/bbs/topic.php?id=372890&page=999 - joevill, on 10/12/2007, -1/+1I really need to learn this! Thanks!
- phparion, on 10/12/2007, -0/+0hi guys, thanks for posting so much feedback on my tute though let me clear a few things,
to define int as string in salary example is a typo and I am sorry for that in fact when you write an article in ten mins you do such mistakes and if you are writer yourself you will understand my point.
some people are crticising just for criticism, dudes, I have already posted four articles on setting up your php environment on windows and linux both and you must read my article again i have given links for those articles too.
anyway, thanks for your feedback. in my next articles I will try to avoid typos - scuzzman, on 10/12/2007, -1/+1I don't know if that's a valid link or not (and I'm not checking), so I dugg you down. I hope others follow this example. If you've got something pertinent to post, please don't mask the URL.
- plhearn, on 10/12/2007, -8/+8Shouldn't that be $total_salary = $salary + $bonus;? You may want to read that guide over one more time.
- yogastore, on 06/30/2008, -0/+0http://astore.amazon.com/la.crosse.atomic.clock-20
http://astore.amazon.com/la.crosse.technology.wire ...
http://astore.amazon.com/upright.bagless.vacuum-20
http://astore.amazon.com/dyson.upright.vacuum-20
http://astore.amazon.com/hoover.bagless-20
http://astore.amazon.com/hoover.canister-20
http://astore.amazon.com/pyrex.storage-20
http://astore.amazon.com/pyrex.storage.lids-20
http://astore.amazon.com/inflatable.bed-20
http://astore.amazon.com/aerobed.inflatable.bed-20 - jinexile, on 10/12/2007, -2/+1Considering that MySQL AB has decided to stop providing binaries to Windows developers I think we will see a significant rise in the use of Postgre
- glomph, on 10/12/2007, -1/+0PHP main
http://tinyurl.com/2yaadc
A good list of tutorials on newgrounds. -
Show 51 - 57 of 57 discussions



What is Digg?
Check out the new & improved