Gyroscope / Record Detail View

In the previous chapter we have created place holders for displaying landlord details.

In landlords.js (Client Handler):

  addtab('landlord_'+llid, llname,

In myservices.php (Server Handler):

case 'showlandlord':
  include 'icl/';

Now we focus on

function showlandlord($llid=null){
  if (!isset($llid)) $llid=GETVAL('llid');
  global $db;
  <div class="section">
  $query="select * from landlords, persons
  where landlords.personid=persons.personid
  and landlords.llid=$llid ";
  <input id="llfname_<?echo $llid;?>" value="<?echo $fname;?>">
  <input id="lllname_<?echo $llid;?>" value="<?echo $lname;?>">
  <button onclick="updatelandlord('<?echo $llid;?>');">

The updatelandlord handler is first implemented in JavaScript and then processed on the server side.

  var ofname=gid('llfname_'+llid).value;
  var olname=gid('lllname_'+llid).value;

  reloadtab('landlord_'+llid, ofname+' '+olname,
      if (document.viewindex==0)

The above function performs a few tasks. It gathers the values from the landlord form. Note how each field ID is made unique by appending the unique landlord ID. The form values are then concatenated to a parameter string, together with the updatelandlord command. By invoking the reloadlab function, the tab title is instantly replaced by the new, specified values. The content of the tab will be replaced by the server side response. Upon server call back, the landlord list on the left of the screen is also updated if the list is currently visible.

Next we need to implement the server-side handler.

Add a clause in the message switch in myservices.php:

case 'updatelandlord':
  include 'icl/';

Then create in the icl folder:

include 'icl/';
function updatelandlord(){

  global $db;

  $query="update landlords set
  fname='$fname', lname='$lname'
  where llid=$llid";


The above function parses the values from the parameter string, updates the database with new values and displays the updated content.

The GETVAL function ensures that the input value is numeric. GETSTR is a wrapper function for $_GET; it detects Unicode strings and encodes the value correctly.

The showlandlord function is defined in a separate file so it's important to include the file at the beginning of the script.

Now review the files we've just created or modified and pay attention to the piggy-backing mechanism. In the updatelandlord JavaScript function, we could have simply sent a request for updating the record; and upon completion, send another request for displaying the record. Instead we send a single updatelandlord event, and it's up to the server-side handler to both update the data and return the new result. The file is structured to be called by both myservices.php or inside another function.

Also note how file dependencies and parameter parsing are all done in the implementation of server handler. The switch clause in myservices.php remains simple and agnostic of the underlying structure.

Table of Content

Our Services

Targeted Crawlers

Crawlers for content extraction, restoration and competitive intelligence gathering.

Learn More

Gyroscope™ ERP Solutions

Fully integrated enterprise solutions for rapid and steady growth.

Learn More


Self-updating websites with product catalog and payment processing.

Learn More