Jun 3, 2009

Make a database driven website in 3 steps

Today every company had to have a website, it is something like having a telephone number or a company address. A lot of companies do not have yet a budget for making a website, they think it is very expensive, and they are right. If you use a web developer in Europe you will need a couple of thousands of Euros to make a simple website to present your company.

In this article I will give a simple tutorial how to publish your database report without the need for a web-developer, something simple but yet very powerful, with your Microsoft access database.

This method is best way for web designers, who know how to make a web page in HTML, but do not know how to connect it with the database, without using PHP or ASP.

First step: create your report page

To show your report online, you will need a database access file and a HTML file which will show the report or the query results.

We will create the databse in Microsoft access, I will create a database and name it as biblio and create a table and name it Titles, we will make these fields:

  • ID as number data type which will be our primary key also.

  • Name as text data type

  • Publisher as text data type

  • PublishYear as text data type

I will fill it with some data and save it, and we have a database file.

If you have a design for your report you will need to slice it and make a HTML page, you can use GIMP on linux or Photoshop on windows, then use any HTML editor or text editor to make the HTML code.

I will use a simple example using WhizBase Server Pages (WBSP) to develop this report. WBSP is a very powerful tool for publishing databases online with a very simple code, it is not like classic web programing languages.

Create the header:

Every WBSP page have a header, it is a place where we put some information needed by the server, everything we write in this section will not apear in our page. This section contains the variables that are essential for processing WBSP file. Here you put information about the database, recordset, template, error template, log file, redirection, etc. We will simply say for the server to connect to our access database and select a table, list for example 10 records only and make a pagiation.

1 [FormFields]

2 wb_basename=biblio.mdb

3 wb_rcdset=Titles

4 WB_Command=Q

5 WB_MaxRec=10

6 <!--WB_BeginTemplate-->

[FormFields] is the starting tag for the section, when the server sees this code it will start receiving our commands. wb_basename=biblio.mdb is our database file, I have putted our database in the same folder as my HTML file so I am calling it directly. The server will look for the file name what ever we give as a path for it after wb_basename and connect to the database file. To specify which table we will select we use wb_rcdset=Titles, as you see I will select the table Titles. We told the server which database file to connect and which table to select, now we need to tell it what to do, and in our case is query, using the command WB_Command we give it a value Q and we did it. Finally we want to limit our results, let us show 10 records by page. We can skip this line and it will list the whole table, but what if we have a table with 10 000 records or more, do you really want to show it all in one page? So we will use WB_MaxRec=10 and that is all what we need. Now give the server a simple comment like command <!--WB_BeginTemplate--> which says to the server begin interpreting the template.

Create the body (template):

After creating the header setion we have to create the template, and that is very simple, it is our HTML code with simple lines of WBSP code where we want to show our data.



<title>Simple DB report page</title>




<tr><th>ID</th><th>Name</th><th>Publisher</th><th>Publish Year</th></tr>





<div align='center'>$wbnavigator</div>



In the template we want to view ten records in a table and then show the navigation bar where users can go next or previus page to see more records.

The most important code in this template is <!--WB_BeginDetail--> and <!--WB_EndDetail--> which represents the start and the end of the looping function, everything between these two will loop for as many times as records we want to show. If the query returned 10 records it will loop for ten times. Between these two commands we will show the records using the function $wbf[fieldname], in our case we are viewing four fields in the table and WBSP will replace every one with the field value in the table.

Finally we have $wbnavigator which will generate for us the navigation links automatically, this is a very cool command, we do not need to calculate anything, it will automatically create as many pages as we need.

We will save all this as defaut.wbsp file, where the extension wbsp will say to the server that this file have a WBSP code in it.

Second step: Create a search form

In the previous step we have made a report page, now we need a filtering form, for example what if we do not want to view all the records, we want to view just records for the publish year 2007.

Create a file named as «search.htm», in this file we will not need any WBSP code, we will only make a HTML form with inputs and a submit. We only must take into account one thing, how we will name our inputs, because WBSP have its automatic mechanism for catching get and post values.



<title>Search filter file</title>



<form action='default.wbsp' method='post'>

ID <input type='text' name='wbf_id' /><br />

Name <input type='text' name='wbf_name' /><br />

Publisher <input type='text' name='wbf_publisher' /><br />

Publish Year <input type='text' name='wbf_publishyear' /><br />

<input type='submit' value='submit' />




As you can see we have used a pure HTML, but we have also used a specific naming method in the input names. WBF_ID is WBF_ + ID where WBF_ is WhizBase prefix and ID is the name of the table field. WhizBase catches all the get and post data and filters them, then takes all the post and get data with prefix WBF_ and sends them to the query.

For example if we put a value 2000 in «Publisher Year» input, it will be a post value in the variable wbf_publisheryear, WhizBase will filter it and catch it because it has wbf_ prefix and then send it as a database query as «publisheryear = 2000».

Third Step: Upload everything online

Finally, we have a form file, a report file and a database. We do not need anything else. Now just upload the 3 files online in the same folder on a server which supports Whizbase or install Whizbase on your Windows server and put these files on the server and you will have a ready report and a filtering system.

For more information about WhizBase or to download it for free you can visit http://www.whizbase.com

1 comment:

son cho said...

Trung niên phụ nhân nói xong, một thanh kiếm xanh biếc đã xuất hiện ở trong tay của nàng, thân hình lao tới, thẳng hướng về phía Hỗn Thế Ma Vương mà công kích.

- Thủy Thanh, chỉ bằng vào ngươi mà muốn đối phó với ta sao, thực lực của ta cho dù chưa khôi phục nhưng cũng đủ để thu phục ngươi.

Hỗn Thế Ma Vương nhẹ nhàng nói, hai tay của hắn xuất thủ, một thanh trường kiếm màu đen xuất hiện, mười đạo kiếm khí bén nhọn bắn ra, ngăn cản kiếm quang công kích của trung niên phụ nhân. “Xoẹt xoẹt xoẹt” Hai người giao thủ mấy lần, thân thể của phụ nhân kia đã bị ngăn cản, xem ra đã rơi vào thế hạ phong.
game mu
cho thue phong tro
nhac san cuc manh
tổng đài tư vấn luật
văn phòng luật
tổng đài tư vấn pháp luật
thành lập công ty
chém gió
trung tâm ngoại ngữ
- Ta đã nói rồi ngươi không phải là đối thủ của ta.

Hỗn Thế Ma Vương không hề dừng lại, tung người xuống lần nữa hướng về phía vô tận thủy vực bay đi, ma khí nồng nặc đuổi theo phụ nhân áo lục.

- Hỗn Thế Ma Vương, ngươi đừng tưởng là có thể bắt ta, Thủy Tuyệt kiếm trận.

Phụ nhân áo lục lạnh lùng nói, nhìn thấy Hỗn Thế Ma Vương đánh về phía mình, thủ