You can also apply selection criteria in your call to getGroups(), so as to return only a specific subset of records. Consider the following variant of the example above, which only returns those groups located in California:
<?php
// include classes
include("../include/patDbc.php");
include("../include/patUser.php");
// initialize database layer
$db = new patMySqlDbc("localhost", "db211", "us111", "secret");
// initialize patUser
$u = new patUser(true);
// connect patUser to database
$u->setAuthDbc($db);
// set tables
$u->setAuthTable("users");
$u->setGroupTable("groups");
// get group list
$list = $u->getGroups(
array("gid", "name", "dsc", "loc"),
array( array("field" => "loc", "value" => "CA",
"match" => "exact") )
);
// print as table
echo "<h2>Groups</h2>";
echo "<table border=1>";
echo "<tr>";
echo "<td><b>GID</b></td>";
echo "<td><b>Name</b></td>";
echo "<td><b>Description</b></td>";
echo "<td><b>Location</b></td>";
echo "</tr>";
// iterate over list
foreach ($list as $l)
{
echo "<tr>";
echo "<td>" . $l['gid'] . "</td>";
echo "<td>" . $l['name'] . "</td>";
echo "<td>" . $l['dsc'] . "</td>";
echo "<td>" . $l['loc'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>