Latest Entry

Understanding URL Variables



Over the past couple weeks I realized there isn't really much information about how dynamic web pages work. The lack of this information makes it harder for new developers to grasp these topics that are fairly simple, but may seem hard without a good example. So the next couple articles are going to cover some of these topics. If you have a topic you would like for me to cover be sure to let me know in the comments below.

On ward to Url Variables.

Url variables is one of the first topics to learn for a new developer wanting to move from static web sites to dynamic sites. Url variables, also called query strings in some languages(asp.net), allow a variable to be passed from one page to another with very little overhead and very little code.

We have all seen the sites, such as mine here, where they have a url such as corymathews.com/?id=12 or something similar. These extra items after the ? are called url variables and I am going to explain what these are, what are they used for, and how do they work?

What are url variables?

Url variables allow developers to  pass multiple values from one page to another in order to display different results every time the same page is loaded. This saves the developer from having to make hundreds of pages which are exactly the same. This is mainly because doing so wouldn't be very realistic or good for any budget.

How do url parameters work?

Take a look at the following link:

http://www.osguide.net/Software/index.php?p=2

We see a couple different parts. We see the domain osguide.net a directory named Software the current page index.php and then we see a ?p=2. This ?p=2 is a url variable setting the variable "p" equal to 2. In this case its being used as a variable to store the current page for my pagination script on the site, but it could be for just about anything. When the page is first loaded I have programmed it page to look to see if the variable p is declared in the url bar. If it is declared then my page knows to display the corresponding page of results, in this case 2. On the other hand you must always take into account if the url parameter is not declared. In my example here if p was not in the url I would consider this page 1 and thus set p to 1.

A thing to note here is that this url can be rewritten as http://www.osguide.net/Software/?p=2 since the index.php is understood and not actually needed.

What if you want to pass multiple parameters? This can be easily accomplished, with the & symbol. For instance in the previous example If I also wanted to set the variable 'R' I would simple use a url like so:

http://www.osguide.net/Software/index.php?p=2&r=3

This can go on and on for as long as you like. Take a look at some of the sites you go to such as gmail, they may pass quite a few different url variables, mainly depending on your browser. All you have to do is keep adding the & in between every variable.

So What are url parameters used for?

Probably most common use for url parameters is to associate the correct information to display from a database. The way this works logically is very simple. A page is set up kind of like a template for content without any "real" content in it. Then from the url variable passed in a query is run on a database and the related page's contents are returned from the database to be displayed on the page. This allows a developer to create one page to show the details of anything, such as this article, without having to create a different page for every article.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Recent Entries

Searching Tips for Opera

Searching in opera is easier and more customizable then ever. Without any add-ons you have 3 powerful ways to search. The first and most powerful search method is the address bar. By simply typing more than one word such as "Web Development" Opera will assume that you wanted to search for "Web Development" and go to your default search engine to display the results of this search. Yes Firefox fans this is where the idea for the new address bar searching came from for v3.

Read More..

If you enjoyed this post, make sure you subscribe to my RSS feed!

Wordpress 2.6

Another excellent upgrade from the guys over at Wordpress.org. They have included a couple small updates as well as some larger updates such as support for gears! I haven't gotten to try it yet but will be in the next day or two. I can only hope the speed difference is as good as it claims to be.

Here is a short video they released that talks about all the new features of Wordpress 2.6.
Read More..

If you enjoyed this post, make sure you subscribe to my RSS feed!

SaveTheDevelopers.org

Recently I was introduced to the site SaveTheDevelopers.org. Their mission is simple "Save A Developer. Upgrade Your Browser." They want to speed up the transition from IE6 to a modern browser. What makes SaveTheDevelopers.org so much better than the rest is that it is much more professional looking than any other anti-IE6 "movement" site. Most anti-IE6 sites simply bash IE6 and never tell you why it really is better. They give off the saying that it is better because I said so, which what IE6 user is going to switch because of that? Seriously? Read More..

If you enjoyed this post, make sure you subscribe to my RSS feed!

The Best Free Media Player for Vista is…

This time around the Best Free Media Player for Vista it is going to have to go to..
Read More..

If you enjoyed this post, make sure you subscribe to my RSS feed!

Songbird 0.6

This little guy was quite impressive. It has a really slick looking and easy to use UI. It only took me a couple seconds to learn how to get around, probably because it looks VERY similar to another media player.. itunes anyone? Although it looks a lot better then itunes, it needs to be changed.
Read More..

If you enjoyed this post, make sure you subscribe to my RSS feed!