sqlfield
tags and the attributes of the sqltemplate
tag. Adding multiple tables, alieses, or functions is actually pretty
straightforward:<?php
include('Sparse.php');
SparseThisPage('username', 'password');
?>
<html>
<sqltemplate type="display" database="myDB" tables="employees AS e,
managers AS m"
limit="10" constraints="WHERE e.managerID=m.id AND mname != 'John
Smith'">
<table border="1">
<sqlrow>
<tr>
<td><sqlfield name="employeeID"
/></td>
<td><sqlfield name="e.name"
/></td>
<td><sqlfield name="m.name AS mname"
/></td>
<td><sqlfield name="concat(e.address, e.city)"
/></td>
</tr>
</sqlrow>
<tr><td colspan="2"
align="center">
<sqlaction type="prev"
/><sqlaction type="next" />
</td></tr>
</table>
</sqltemplate>
</html>
SELECT employeeID, e.name, m.name AS mname,
concat(e.address,
e.city) FROM employees AS e, managers AS m WHERE e.managerID=m.id AND
mname != 'John Smith'
(As mentioned earlier, the primary keys of all tables are
also
selected, and the limit clause is changed slightly.) So if you know
what your SQL query would look like, you can easily translate that into
Sparse tags.sqlfield
tag which is a function to have type text
- i.e. plain text, not editable.deleteTables
attribute in sqltemplate
.
sqlfield
name as "e.name AS ename" and "m.name AS mname") to differentiate them.
Similarly, you should alias tables rather than using a database
identifier, e.g. "myDatabase.table1 AS myTable1" in the tables
attribute of sqltemplate
.fields
Attributesqltemplate
tag, and simply reference the aliased name in the body of the template.
You can do this by using the fields
attribute. Doing this will
cause the above template to look like this:<?php
include('Sparse.php');
SparseThisPage('username', 'password');
?>
<html>
<sqltemplate type="display"
database="myDB"
fields="employeeID, e.name, m.name AS mname,
concat(e.address, e.city) AS address"
tables="employees AS e, managers AS m"
limit="10"
constraints="WHERE e.managerID=m.id AND mname !=
'John Smith'">
<table border="1">
<sqlrow>
<tr>
<td><sqlfield name="employeeID"
/></td>
<td><sqlfield name="name"
/></td>
<td><sqlfield name="mname"
/></td>
<td><sqlfield name="address"
/></td>
</tr>
</sqlrow>
<tr><td colspan="2"
align="center">
<sqlaction type="prev"
/><sqlaction type="next" />
</td></tr>
</table>
</sqltemplate>
</html>
sqlfield
tag by giving it the name concat(e.address, e.city) - i.e. repeating
the exact same function you gave it earlier. Still, it's usually nicer
to alias the name.
query
attribute of sqltemplate
. This will force the
template type to be display.Previous: Template Types | Advanced Queries | Next: Quick Templates