Search a database in categories

We create a form that will submit the title of a page to the search SQLReport. This will search for data in the WebGUI database wich looks like the keyword you submit and only in assets where the category is set in the meta-data of the asset.

Category:
Users
Assets
Collaboration
Advanced
Search for an asset with keyword:

  • Debug: Query:SELECT DISTINCT title, url FROM assetData LEFT JOIN metaData_values USING (assetId) WHERE title like concat('%',?,'%') AND ? <> '' AND ( metaData_values.value = concat('',trim(?),'') OR metaData_values.value = concat('',trim(?),'') OR metaData_values.value = concat('',trim(?),'') OR metaData_values.value = concat('',trim(?),'') ) AND assetData.revisionDate = (SELECT MAX(maxAssetData.revisionDate) FROM assetData as maxAssetData where assetData.assetId=maxAssetData.assetId)
  • Debug: Processed Placeholder parameters:,,,,,

The form html looks like:

<form>
Category:<br />
<input name="category1" value="Users" type="checkbox" />Users<br />
<input name="category2" value="Assets" type="checkbox" />Assets<br />
<input name="category3" value="Collaboration" type="checkbox" />Collaboration<br />
<input name="category4" value="Advanced" type="checkbox" />Advanced<br />
Search for an asset with keyword: <input name="searchtitle" type="text" /><br />
<input value="submit" type="submit" />
</form>

The placeholders are:

form:searchtitle
form:searchtitle
form:category1
form:category2
form:category3
form:category4

The query is: 

SELECT DISTINCT
title,
url
FROM
assetData
LEFT JOIN
metaData_values
USING
(assetId)
WHERE
title like concat('%',?,'%')
AND
? <> ''
AND
(
metaData_values.value = concat('',?,'')
OR
metaData_values.value = concat('',?,'')
OR
metaData_values.value = concat('',?,'')
OR
metaData_values.value = concat('',?,'')
)
AND
assetData.revisionDate = (SELECT MAX(maxAssetData.revisionDate) FROM assetData as maxAssetData where assetData.assetId=maxAssetData.assetId)

The template looks like:

<a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a>

<tmpl_if session.var.adminOn>
<p><tmpl_var controls></p>
</tmpl_if>

<tmpl_if displayTitle>
<h2><tmpl_var title></h2>
</tmpl_if>

<tmpl_if description>
<tmpl_var description>
<p />
</tmpl_if>

<tmpl_if debugMode>
<ul>
<tmpl_loop debug_loop>
<li><tmpl_var debug.output></li>
</tmpl_loop>
</ul>
</tmpl_if>

<tmpl_loop rows_loop>
<a href="<tmpl_var row.field.url.value>"><tmpl_var row.field.title.value></a><br />
</tmpl_loop>