User Tools

Site Tools


browse_box

This is an old revision of the document!


Browse Box

One of the most common needs of any website is to list data. The wtkBuildDataBrowse PHP function makes it extremely easy to do this.

As an example of the simplest use, these few lines create a fully functioning page by calling wtkFillBrowsePage which is a wrapper for both wtkBuildDataBrowse and wtkMergePage.

<?php
$gloLoginRequired = false;
require('wtk/wtkLogin.php');

$pgSQL = 'SELECT `FirstName`, `LastName`, `City` FROM `wtkUsers`';
wtkFillBrowsePage($pgSQL);
?>

Full Tutorial Video

Column Alignment

All columns will be left justified by default. To make a column center or right justified, just assign it in the PHP global variable like this:

$gloColumnAlignArray = array (
    'Priority' => 'center',
    'Amount' => 'right'
);

Totaling Columns

Choosing which columns should be summed is easy also. This only sums the values shown in the list. So if your list is for 200 and your page navigation is set to 50, it will only show the first 50 rows and the total for the rows which are visible.

$gloTotalArray = array (
    'OrderCount' => 'SUM'
    'TotalInvoiced' => 'DSUM'
);

Passing SUM tallies the numbers. Using DSUM makes it so the sum at the bottom uses your chosen currency. The nubmer formatting and currency setting are defined by these two global variables which you set in the wtk/wtkServerInfo.php file.

$gloPHPLocale = 'en_US';  // determines number formatting
$gloCurrencyCode = 'USD'; // determines currency code in number formatting

Sorting Functionality

The wtkSetHeaderSort function can take 1, 2 or 3 parameters. Note, as usual spaces will be automatically be inserted for WordCaps or snake_case. For example, 'FirstName' will be changed to 'First Name'.

Note that in order for Sort Order to work, it requires the SELECT to have an ORDER BY.

One Parameter

PagesVisited

This uses column named `PagesVisited` and makes header as “Pages Visited” and sorts by this column.

Two Parameters

LookupDisplay, USA State

This uses column named `LookupDisplay` but shows the header as “USA State”. It sorts by the `LookupDisplay` column.

Three Parameters

DOB, Birthday, u.`BirthDate`

This uses column named `DOB` but shows the header as “Birthday”. It sorts using u.`BirthDate` column. This is really important when formatting causes problem with sort order. For example if your date format is '%b %D, %Y' then sorting by that would not give the results you want.

Example

Here is an example SQL query and the associated Sort Options.

SELECT p.`UID`, u.`FirstName` AS `Owner`, p.`PetName`, p.`City`,
  DATE_FORMAT(p.`BirthDate`,'%b %D, %Y') AS `DOB`
FROM `pets` p
  INNER JOIN `wtkUsers` u ON u.`UID` = p.`UserUID`
  INNER JOIN `wtkLookups` L ON L.`LookupType` = 'USAstate' AND 

Sortable Columns Owner City, Town DOB, Birthday, p.`BirthDate`

So for the above example, in the PHP you would simply add this before the wtkBuildDataBrowse call.

wtkSetHeaderSort('Owner'); // Defaults column name but can change with second parameter
wtkSetHeaderSort('City', 'Town');
wtkSetHeaderSort('DOB', 'Birthday', 'p.`BirthDate`');
// when third parameter exists it is used for sorting of first parameter's column

WTK Page Builder

If you use the WTK Page Builder it will create a browse PHP page for you and have in the code comments all the main features.

Full Tutorial Video

browse_box.1733103596.txt.gz · Last modified: 2024/12/02 01:39 by wtkadmin