Showing posts with label show your database. Show all posts
Showing posts with label show your database. Show all posts

Monday, September 27, 2010

Displaying records from database table

The easiest (and fastest) way for displaying the database records is shown in following example:
[FormFields]
wb_basename=biblio.mdb
wb_rcdset=Titles
WB_Command=Q
WB_TempName=$default$
This will produce simplest report containing all fields from table Titles in a HTML table, on a white background, broken in pages containing 20 records per page. This report is not completely useless and usually is used for testing purposes.
However, to make report a little bit nicer we will do small changes in previous example:
[FormFields]
wb_basename=biblio.mdb
wb_rcdset=Titles
WB_Command=Q
WB_MaxRec=10




Simple database example


$wbdetail[t]
Now we have added some title to the report and some HTML formatting using $WBDetail[T] function and CSS styles. We also changed the number of records per page using WB_MaxRec.
With further modifications we can include Author's and Publisher's names instead of their ID numbers, and sort titles by year in descending order as shown in following example:
[FormFields]
wb_basename=biblio.mdb
WB_RcdSet=(Authors inner join titles on authors.au_id=titles.au_id) inner join publishers on publishers.pubid=titles.pubid
WB_DBFlds=Title,[Year Published],ISBN,Authors.Name as Author,publishers.Name as Publisher
WB_Command=Q
WB_MaxRec=10
WB_Order=[Year published] desc




Simple database example


$wbdetail[t]
To enable search though this recordset we should add the search form and modify the recordset definition as shown in following example:
[FormFields]
wb_basename=biblio.mdb
WB_RcdSet=(select Title,[Year Published],ISBN,Authors.Name as Author,publishers.Name as Publisher,Authors.Name,publishers.Name from (Authors inner join titles on authors.au_id=titles.au_id) inner join publishers on publishers.pubid=titles.pubid)
WB_Command=Q
WB_MaxRec=10
WB_Order=[Year published] desc




Simple database example
















$wbdetail[t]

This looks much better, but in some cases there is a need for placing the database field in a specific location on your report, or even not using HTML at all. In that case we do not use $WBDetail function but some (or all) of database field functions $WBF, $WBRF. In the following example we will modify the code so it will return previous recordset in XML format:
[FormFields]
wb_basename=biblio.mdb
WB_RcdSet=(Authors inner join titles on authors.au_id=titles.au_id) inner join publishers on publishers.pubid=titles.pubid
WB_DBFlds=Title,[Year Published],ISBN,Authors.Name as Author,publishers.Name as Publisher
WB_Command=Q
WB_MaxRec=$all$
WB_Order=[Year published] desc
WB_ContentType=text/xml



$wbmrepl[$wbf[Title]|',&|',&]
$wbf[year published]
$wbf[isbn]
$wbf[Author]
$wbf[Publisher]
We modified WB_MaxRec to special value $all$ (this will show all records from recordset in a single report page) and set the WB_ContentType variable to text/xml. Note that we also had to use $WBMREPL function to replace apostrophe and ampersand characters in field "Title".

read more