Website Databases
Home  |   FAQ   |   Forums  |   Contact Us
PHP Magic
Overview
PHP Magic Demo
Download Free Trial
Download Free Samples
Order Now
Database Software
Access to MySQL
Excel to MySQL
Members Login Script
PHP Reports Generator
Other Software
PHP Form Processor
Web Form Security
Convert HTML to PHP
Convert HTML to ASP
Website Databases
About Us
F.A.Q.
Contact Us
Forums
Order Now
PHP form Image verification
Con vert HTML to PHP form
PHPMagic  Specials   Database Tools   Download   Samples   Order
Home » About Us

PHPMagic Filters - How-to Guide

Creating Default Or Pre-Applied Filters

In many cases, you'd like users accessing your tables to see filtered data directly instead of forcing them to manually define filters. This is specially applicable if your users are novice and feel uncomfortable with the advanced filters provided by PHPMagic.


Note: Assuming that you have a good knowledge of HTML and how HTML forms work. If not, you may wish first to take some HTML lessons. You may try the excellent tutorials on HTMLGoodies.com


So, we'll try here to highlight how to create a default filter that automatically applies when users access a table. Let's first see how PHPMagic filters work. Below, you can see the filters page where users define filters.

Empty filters page as generated by AppGini 2.5 Professional edition.
Empty filters page as generated by PHPMagic edition.


You can note that PHPMagic offers up to 12 filters divided into 3 groups -- each group containing up to 4 conditions. Simply speaking, filters and grouping work in a manner similar to this:

Show me all records that satisfy (F1 and F2 and F3 and F4) and (F5 or F6 or F7 or F8) and (F9 or F10 or F11 or F12)

The above expression simply means that we want to see all records that satisfy ALL of the first 4 conditions and ANY of the next 4 conditions and ANY of the last 4 conditions. Of course, users don't have to define all 12 conditions. Even if they define one single condition, it will apply once they click the "Apply Filters" button (the sunglasses button at the bottom of the filters page).

Let's define and apply some filters then view the source code of the filters page to see the inner works of PHPMagic filters. Here are some filters that we applied to a table:

We have applied some filters to our table.

We have applied some filters to our table. The filters here mean "Show me all records where (author begins with the letter 'A' and doesn't contain the letter 's') or (year_born is after 1925)"


If we view the HTML source of the above filters page (right-click your browser window, and select "View Source"), we can get a very good idea about how filters are defined. And we can can accordingly mimic the filter definitions to create our own default filters. These are the important parts of the code we'll see:
<form method=post name=myform action='authors_view.php'>
The above code defines a form that posts data to the file called "tablename_view.php", where tablename is the name of the table you want to define filters for.

Next, we see the code that allows users to select the field name used in the first condition in the filter:
<select name='FilterField[1]' class='Option' style=''>
	<option value='' class=Option></option>
	<option value='authors.Au_ID' class=Option>Au_ID</option>
	<option value='authors.Author' selected class='SelectedOption'>Author</option>
	<option value='authors.Year_Born' class=Option>Year_Born</option>
	</select>
Notice the name of the above <select>: FilterField[1] The selected option here is the third one, which has a value authors.Author.

Next, we see the HTML code of the "comparison operator" for the first condition:
<select name='FilterOperator[1]' class='Option' style=''>
	<option value='' class=Option> </option>
	<option value='<=>' class=Option>Equal to</option>
	<option value='!=' class=Option>Not equal to</option>
	<option value='>' class=Option>Greater than</option>
	<option value='>=' class=Option>Greater than or equal to</option>
	<option value='<' class=Option>Less than</option>
	<option value='<=' class=Option>Less than or equal to</option>
	<option value='like' selected class='SelectedOption'>Like</option>
	<option value='not like' class=Option>Not like</option>
	</select>
Again, the name of the above <select> is FilterOperator[1]. The selected value is like. The last part of the first condition is the "comparison value". The HTML code for this part is:
<input size=25 type=text name=FilterValue[1] value="A%" class=TextBox>
As of the second condition, we notice that every condition thereafter begins with a <select> for choosing "And" or "Or". For example, the second condition contains the following code:
<select name='FilterAnd[2]' class='Option' style=''>
	<option value='and' selected class='SelectedOption'>And</option>
	<option value='or' class=Option>Or</option>
	</select>

Conclusions

It's obvious now that the filter contains several conditions. Each condition is defined using 4 parts:

Name Value
FilterAnd[i] And, Or
FilterField[i] table_name.field_name
FilterOperator[i] <=>, !=, >, >=, <, <=, like, not like
FilterValue[i] Any numeric, text, or wild-card value


In the above table, [i] represents the condition number. If you're defining the first condition, replace i with 1. If you're defining the second condition, replace i with 2, and so on. Notice that for the first condition, there is no need to define FilterAnd[1].

Finally, we are ready now to create our own default filters page. To do so, open your Windows NotePad (or any other text editor), and paste the code below into it:
<form method="post" name="myform" action="authors_view.php">

	<input type="hidden" name="FilterField[1]" value="authors.Author">
	<input type="hidden" name="FilterOperator[1]" value="like">
	<input type="hidden" name="FilterValue[1]" value="A%">

	<input type="hidden" name="FilterAnd[2]" value="and">
	<input type="hidden" name="FilterField[2]" value="authors.Author">
	<input type="hidden" name="FilterOperator[2]" value="like">
	<input type="hidden" name="FilterValue[2]" value="%s%">

	<input type="hidden" name="FilterAnd[5]" value="or">
	<input type="hidden" name="FilterField[5]" value="authors.Year_Born">
	<input type="hidden" name="FilterOperator[5]" value=">">
	<input type="hidden" name="FilterValue[5]" value="1925">
	
	<input type="submit" value="Show me filtered authors">
</form>
The above code creates a form containing several hidden variables defining the filters, and one button that submits the form:



When users click that button, they see the table with all the predefined filters applied to it. Notice in the above code that we didn't have to define all the 12 conditions. We need only define the variables for the conditions that we'll use.

Of course, you don't have to submit the form using a submit button. You can use an image submit:
<input type="image" src="myimage.gif">
Or you can use a normal hyperlink:
<a href="#" onclick="myform.submit();">Show me filtered authors</a>
We have an html filters template that you can edit to create your own predefined filters. Click here to download the filters template
© 2003-2008 Website Databases All rights reserved
Home  |  PHPMagic  |  Database Tools  |  Download  |  Samples  |  Order  |  FAQ  |  Forums  |  Contact