1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley
Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

PHP Magic 8-Ball

Thursday July 6, 2006
I admit it, once in awhile I waste time time on silly websites with card tricks, ghosts jumping out of pictures, and coin flips. You know the ones... they get passed around to you in emails... don't pretend you don't, we're on to you! In the spirit of these time burners, our new tutorial shows you how to make an online magic 8-ball using PHP.
Comments
July 7, 2006 at 9:48 am
(1) hagakure says:

This is more a question then comment, why did you use multiple IF statements instead of a switch loop? Wouldn’t the latter have been much easier and more compact?

– hagakure

July 10, 2006 at 10:06 am
(2) php says:

Hello!

There was no programming reason why I did it that way over a switch loop :) I tend to lean towards if/elseif anyway (no particular reason) and I hadn’t covered switch yet on the site (didn’t want to confuse people who are just learning by using a function we had not yet covered) :)

But alas, since you gave me this reminder I’ll be adding some info on switch () today :)

July 10, 2006 at 12:45 pm
(3) hagakure says:

Oh…

Well that makes sense, I haven’t had the chance to read all of the articles or I would have known that…

Keep up the good work.

– hagakure

July 13, 2006 at 3:25 pm
(4) Jennifer Kyrnin says:

This is great. A “Magic 8-Ball” is one of the first programming feats I did in my first Web job. I did it as a joke, and it was a lot of fun to direct people there when they asked me questions. :-)

December 21, 2006 at 4:43 am
(5) Omri Shaffer says:

Hello,
I believe this code is correctionful. I mean, it wastes alot of space, uses conditionals wrongly, etc.
______________________
One problem, I am using the Zend Enviorment and it tells me that $question is undeclared.
Help please. :)

December 24, 2006 at 7:48 am
(6) David Langford says:

Thanks for the amusing script, which I adapted as a bit of Christmas silliness for friends. Some found it didn’t work, apparently because of the smart quotes in echo $_SERVER[’PHP_SELF’]; … changing these puts the intended text in the form’s action attribute, which otherwise is empty. Oddly enough, the buggy version worked for me and most of my visitors.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

©2009 About.com, a part of The New York Times Company.

All rights reserved.