This website is defined in a database

Nearly all the pages you see on CallMeAlan.uk are defined in a MySQL database resident on the web server.

The underlying technology here is Active Server Pages, or ASP. This is a server-side scripting method for dynamic websites, originated by Microsoft. Although ASP has now been superseded by ASP.NET, I have seen no need to "fix what ain't broken", and thus I've stayed with ASP, which provides all I need.

ASP provides the means to write VBScript code in a page, which is interpreted by the ASP engine on the server. ASP scripting code is encapsulated between <% and %> tags. The code is not sent back to the browser, but is replaced by whatever the scripting creates, and thus the end-user never sees and code. Indeed, depending on the complexity of the scripting, the end-result seen by the user may be totally different from the web page as I, the author, constructed it. I'll show you examples of this below.

Given this intrinsic hiding of code, I can write scripts which, for example, connect to the database, providing not only the database address, but also user name and password, without you ever seeing these details. In fact, the database is opened right at the top of this page, but if you View Page Source you'll see nothing.

ASP means I can store page content in a database and call SQL queries to display it as HTML on your screen.
Why would I want to store the content in the database? As all the page contents are in the database, I don't need to edit individual web pages and transfer them to the server via FTP if I, for example, spot a spelling mistake. I simply edit the content directly in the database. To this end I have some software on my Mac which reads all the content and enables its editing locally - no HTML editor, no FTP, just edit the content and it's done. I'll show you.

Here is a screenshot of my local site content editor software, showing the editor for the above div on this page:



So if I needed to change something I simply edit the HTML code in this editor, which updates the entry in the database, and the change is reflected immediately in your browser. No HTML editor, no FTP. Much easier.

I should explain the presence of the tildes in the code shown. If you want to write to a database something like "I wouldn't do that" you'll cause an error, that's because of the single quotation mark. So

insert into table values 'I wouldn't do that'

You can perhaps spot that there are three quotation marks. These should be balanced, so the SQL would fail. Therefore my site content editor stores all single quotation marks as tildes, and translates these into quotation marks prior to display on the page.

And then - how do we actually get the HTML shown in my image and display it? At the top of each page sits an ASP function:

<%
function getcontent(keyword)
    sql="select thecontent from sitecontent where thekey='"&keyword&"'"
    rs=conn.execute(sql)
    getcontent=replace(rs("thecontent"),"[tilde]","'")
end function
%>


Note: I wrote [tilde] there because if I put an actual tilde it would have been replaced!

In other words: construct an SQL statement, execute it against the database, and return it as the result of the function, first converting tildes to quotation marks.

Here's a small part of this very page:



But if you View Source you won't see any of that. Try it.

Incidentally: look at the screenshot of my local site content editor. You may notice this:

<div class="bg-col-white col-indigo w-50 p-15 bt-br-rad15 bt-bl-rad15 div-centre div-shadow ">

You may be wondering - what on earth is that CSS? Indeed, is it CSS? It is.

I've explained this technology in full in my Explaining my approach to CSS Style Sheets, which I encourage you to have a look at.