The Database Journal
03/10/2006
Adjusting Autonumber Increments

03/10/2006
Moving Access Data to Microsoft Excel

03/10/2006
Exporting Access Data with TransferSpreadsheet

03/10/2006
Export Access Data with VBA

03/13/2006
Data Layout in Microsoft Excel

03/17/2006
Excel Text to Number Conversion

03/21/2006
Transposing Excel Ranges

03/25/2006
Access VBA Timer Event

03/29/2006
What is MySQL?

04/02/2006
Microsoft Access Parameter Query Tutorial Video

04/06/2006
How does PHP Work?

04/10/2006
Microsoft Access VBA Tools - References

Click here to view all articles.

Database Design
Website Design
Search Engine Marketing
Home
Contact Us
About Us
Database Journal
Newsletters

How does PHP Work?

PHP is a strange animal. It’s quite close to HTML. If you are totally unfamiliar with what HTML can do, here’s a very basic example:

Let’s say you have a webpage with the words, “My name is Fred” on it.

If you were to write that in HTML, your code would look exactly like this:

My name is Fred

Not very difficult, huh? Well if you wanted to make the word “Fred” bold, then in HTML it would look like this:

My name is <b>Fred</b>

What you’re seeing around the word “Fred” are two tags. An opening tag, and a closing tag. The opening tag is basically saying “Everything after me is BOLD!” and the closing tag is saying, “Everything after me WON’T BE BOLD!”

PHP is similar to using HTML tags like the above example in that you can interject PHP into existing HTML. It’s also a programming language.

PHP always executes on the server, which means that it has nothing to do with your computer while you’re sitting there surfing the net. Some of you might be familiar with clicking on “View” then “Source” when you’re looking at a web page in order to see the HTML that makes it happen. Well, you’ll never see any PHP there because it’s already been executed and only the end result is sent to you.

Let’s say that “Fred” was stored in a PHP variable (a variable is just something that holds a value that you give it – think of it as a container). That variable is “$Name”.

So if your code said:

$Name = “Fred”

Then any time we use “$Name” in our source code, you’re going to see “Fred” on your browser instead.

So all we need to do is find out a way to write code that basically says:

My name is $Name!

Incidentally with PHP you would do it like this:

My name is <? echo $Name ?>!

Looks funny, huh? Well the “<?” and “?>” are opening and closing tags for PHP code. It tells the server to run that PHP code before it continues, and the “echo” places the value of “$Name” in that place. The result would be this appearing on the webpage:

My name is Fred!

We could fill the $Name variable with anything we wanted – “Bob”, “Joe”, or even “Gorgonzola”. In this case, PHP is only spitting that value back out.

I know what you’re thinking …

“Why not just type ‘My name is Fred!’”?

That’s a great question, and one I kept asking until I realized how cool PHP can be. Think of it this way. Let’s say we have a list of 5,000 names that we have to make web pages for.

Can we make 5,000 web pages and upload them? Absolutely. But it might be easier to make one web page and let it show us whatever we want. PHP allows you to do this because it is dynamic.

If I create a page with the words, “My name is Fred!” on it, I know that the page will never change. If I use PHP instead, then I can make the page say whatever I want in place of “Fred”. So instead of 5,000 pages, I only need one page that has a little bit of code to dynamically change the name. This saves me a TON of work!


©2014 Blue Moose Technology, LLC

David Badurina, President of Blue Moose Technology, LLC, is a relational database design expert. David's unique ability to easily explain virtually any technical concept has allowed him to work with companies such as AMD, Motorola, the American Heart Association, and countless small businesses. Learn more about database design right now at http://www.bluemoosetech.com.

Article Publishing and Re-Print Guidelines

You can easily link to this article!

If you'd like to link to this article from your own website, copy and paste the following HTML code onto your page:

On your page, the code will appear like this:

How does PHP Work?