Getting information from matching records

The fetch method

The IMuModule class fetch method is used to get information from the matching records once the search of a module has been run. The server maintains the set of matching records in a list and the fetch method can be used to retrieve any information from any contiguous block of records in the list.

Specifying columns

This section specifies the values that can be included or used as the columns arguments to the IMuModule class fetch method.

A simple example

In this example we build a simple PHP based web page to search the Parties module by last name and display the full set of results.

First build the search page, which is a plain HTML form:

<head>
  <title>Party Search</title>
</head>
<body>
  <form action="a-simple-example.php">
    <p>Enter a last name to search for (e.g. Smith):</p>
    <input type="text" name="name"/>
    <input type="submit" value="Search"/>
  </form>
</body>

Next build the results page, which runs the search and displays the results:

<?php
require_once dirname(__FILE__) . '/../../lib/IMu.php';
require_once IMu::$lib . '/Module.php';
require_once IMu::$lib . '/Session.php';
require_once IMu::$lib . '/Terms.php';

if (! isset($_GET['name']) || $_GET['name'] == '')
{
	header('HTTP/1.1 400 Bad Request');
	print("missing 'name' parameter\r\n");
	exit(1);
}
$name = $_GET['name'];

$terms = new IMuTerms();
$terms->add('NamLast', $name);

$session = new IMuSession('imu.mel.kesoftware.com', 40136);
$module = new IMuModule('eparties', $session);
$hits = $module->findTerms($terms);

$columns = array
(
	'NamFirst',
	'NamLast'
);
$results = $module->fetch('start', 0, -1, $columns);
?>
<!DOCTYPE html>
<html>
<head>
<title>IMu PHP API - A Simple Example</title>
</head>
<body>
<p>Number of matches: <?php echo $results->hits ?></p>
<table>
<?php
    /* Display each match in a separate row in a table */
    foreach ($results->rows as $row)
    {
?>
    <tr>
        <td><?php echo $row['rownum'] ?></td>
        <td><?php echo $row['NamFirst'], ' ', $row['NamLast'] ?></td>
    </tr>
<?php
    }
?>
</table>
</body>
</html>

In this example the name parameter entered via the HTML search page is submitted to the PHP script. The script searches for parties records that have the entered value as a last name and display the parties first and last names in an HTML table.