InternetUniversity: Programming 102
Basically, web developers have a certain set of tools they use to design pages. So, how do they insert content into these layouts? For smaller websites the content is the text on the page written within the HTML. This means that every time there is a change in the content of the page, it must be edited by hand and updated on the web server. For a website like CNN.com which publishes hundreds of articles a day, this would become quite a cumbersome daily task.
Rather than update hundreds of pages a day, web developers create HTML templates in which a space is left to accommodate an article. To put it simply, when a visitor clicks on a link to read an article, the page calls the HTML template on the site’s server, giving it the ID of the requested article. The server looks the ID up in a database, and the template is sent back to the visitor’s screen with the specified article loaded into it. When the visitor clicks on the next article, the same template is called but with a different article ID, and so on. Now let’s go a little deeper.
Connecting a web page and its visitor to a database really involves the use of two types of programming languages. First you need a language the database understands. This is usually some form of SQL, or Structured Query Language. It’s a fairly simple set of commands that allows the programmer to select, insert, update, or delete records from a table in a database. If I wanted to insert this article into the STORIES table of my database, I would write a query that would look like this:
INSERT INTO STORIES (date, author, title, body) VALUES (7/01/01, ‘Mark Kecko’, ‘Programming 102’ ‘All of this text...’)
Now that we have the mechanisms for retaining and displaying data, we can create really dynamic web pages. Let’s say we wanted to create an archive of all the news stories on CNN.com, allowing the visitor to search the archives by date. First we would write the HTML template to display the stories once they were retrieved from the database. Then, using SQL, we would write a query to get all the articles from that day, such as:
SELECT author, title FROM STORIES WHERE date = 7/01/01
Let’s assume we retrieved ten articles from the query. Using a language such as Java, ColdFusion, or ASP we could loop over the results displaying the titles. The choice of language to create this dynamic behavior depends on the individual programmer. I would do the following:
BEGIN LOOP ON STORIES QUERY #title# - #author# IF NOT LAST RECORD GO TO BEGIN END LOOP
This would display the title and author of the ten articles from that day. If there were 100 articles archived on that day, all of them would be displayed and the visitor would then simply click on the title of the article he was searching for. Or, we could allow the visitor to narrow his search with another parameter (such as keyword, author, etc.) using another simple SQL query.
We could also add articles to the archives at any time and not have to worry about changing the template at all. All the aforementioned are scalable, cross-platform programming languages that make it possible to manage the content of any website including text, graphics and—you guessed it—ads.