SourceForge.net Logo
Home | SourceForge | Documentation | FAQ | What's New | To-Do List | Forums | Download | Contact

Sparse - Searching

Sparse not only allows you to navigate amongst data (by using sqlnavigation or the previous/next sqlaction buttons) it also allows you to search for specific values quickly and easily. You can navigate amongst the returned values the same way you can with regular ones! Here's a quick demonstration.

<sqltemplate database="myDB" tables="news" type="display" limit="5">
  <table border>
    <sqlrow>
      <tr><th>Name</th><th>News Title</th><th>E-mail</th></tr>
      <tr><td><sqlfield name="name"></td>
           <td><sqlfield name="title"></td>
           <td><sqlfield name="email"></td>
      </tr>
   </sqlrow>
  </table>
Name: <sqlfield name="name" isSearch="true"> <sqlaction type="search">
<br><sqlnavigation>
</sqltemplate>

That'll print out something like the following:

Name News Title E-mail
Daniel First Update! my_email@email.com
Sarah Second Update! her_email@mail.com
Magic Johnson Update! magic@the-gathering.com
Terry Discworld Update! pratchett@rocks.com
Boutros I Can't Pronounce My Name hgfetbcvnb@serbia.com

Name: 
1 2 3 4 5

Now let's say you enter "Daniel" into the name search box. You'll come up with something like this:

Name News Title E-mail
Daniel First Update! my_email@email.com
Daniel Site Updated. my_email@email.com
Daniel E-mail change. daniel@sparse.com
Daniel Now you can search with Sparse! daniel@sparse.com
Daniel More updates to come. daniel@sparse.com

Name: 
1 2 3

Note that the search terms are appended (ANDed) to the existing constraints, and each search term is ANDed together (i.e. all terms must match). Search terms are substring matches (using SQL's "LIKE" syntax).

Finally, you can use the sqlsearch tag to streamline things. Similar to quick templates, sqlsearch replaces itself with several other tags. For example:

<sqlsearch names="name, email" />

will replace itself with

Name: <sqlfield isSearch="true" name="name" /> Email: <sqlfield isSearch="true" name="email" /> <sqlaction type="search" />

You can use Linking to search via a form or a URL from a different page - this is useful to e.g. show only a specific row as identified by ID.

Previous: Referencing Tags | Searching | Next: Sorting