The Result
Object
If you need finer control over how results are displayed on your page, you can create a Result
object directly in your own script. A Result
constructor takes two parameters: a string containing an SQL query, and a format string. There are no restrictions on the SQL query, but all queries are executed by a MySQL user with very limited permissions (So you can't, say, delete the database).
Within the format string, patterns matching %field%
will be replaced with the data from each row from the database field corresponding to field. Refer to the AI Database table descriptions for a list of valid fields.
For example:
<ul>
<?php
$people = new Result("select * from people","\t<li><a href=\"%Homepage%\">%Firstname% %Lastname%</a></li>\n");
echo $people;
?>
</ul>
<ul>
<li><a href="http://www.cs.utexas.edu/~userFoo">Foo Smith</a></li>
<li><a href="http://www.somesite.org/">Bar Johnson</a></li>
...
<li><a href="http://www.cs.utexas.edu/~spam">John Cleese</a></li>
</ul>
A Result
object also provides a few helper functions to aid in customizing how results are displayed. Example:
<table>
<?php
$pubs = new Result("Select * from pubs where Year >= 2004 order by Year","\t<tr><td>%Year%</td><td>%Title%</td><td>%Ref%</td></tr>\n");
//Display the first 20 results, or fewer (if total < 20)
$max = 20;
if($pubs->getSize() < $max) $max = $pubs->getSize();
for($c = 0;$c = $max; $c++) {
//Display each formatted result
echo $pubs->getFormattedRow($c);
}
?>
</table>
<table>
<tr><td>2006</td><td>Synthesizing lunch using a dead parrot</td><td>Journal of the Flying Circus</td></tr>
<tr><td>2006</td><td>An example title</td><td>Technical Report, 1/22/06</td></tr>
...
<tr><td>2004</td><td>Another example title, without the parrot</td><td>New England Journal of parrots</td></tr>
</table>