home  products examples manual  faq support forum  contact news  login store

More Examples:   View Source:   Checking for empty strings

Free Download

All browsers do not display empty strings properly in a table cell. Part of the table cell borders disappear when attempting to display an empty string. What phpLens does is to automatically insert a non-breaking space " " into the cell. If you want to manipulate the values in a cell that may potentially have an empty cell, you have to check for the empty string. This example shows how you go about checking for an empty string.

In this example: If {country} is not entered into the database, display {country} as "unknown".

This is a Demo. You can not change anything for security reasons.
Back to Grid     phpLens Settings  Column Settings   Choose   Generate PHP Code   Remove All Settings   ?  
FieldFIRSTNAME   Type: string[72]   Change Type
Default Title
Grid Title
Edit Title 2 Fields in Row
New Title 2 Fields in Row
Edit Notes
Use {KEY} to incorporate primary key, and prefix ?EDIT? or ?NEW? to display note only in EDIT or NEW state
Detail Title 2 Fields in Row
Filter Title
Input Dimensions
(suggested size: 48 x 1)
Columns:   Rows:

Power Lens
Lookup Values
Input Type       Enter a lookup to allow check boxes and radio buttons
# check/radio columns
Overlib Text
Search Lookup when editing
Matching above sql with fields
Minimum character length   Search mode   Hide key code
 X: 0-9 A-Z             x: 0-9 A-Z optional       Z: 0-9 A-Z _            z: 0-9 A-Z _ optional
#: 0-9 9: 0-9 optional +: positive numbers only
&: any character ?: any character optional \: escape character >: to uppercase <: to lowercase =EMAIL: email validation
Validation Error Msg
Default New Value
Prefix value with = to execute PHP code and % for SQL function
Optional Editable ColumnEnabled when Column   has value Enter A^B^C, or * for any non-empty value
Power Edit Lens
Grid TD Attributes   (nowrap, width=30%, align=center etc.)
Cell Color grid^title^input  
Color Reference opens in a new window

Section Break Title
Back color   CSS class

WYSIWYG Editor for fields that accept HTML
Do not convert
Special Chars
This Field supports Double-Byte (eg Chinese, Japanese) and HTML tags
Must FillNo   * Must Fill Columns
Read OnlyNo   - Read Only Columns
Visible in GridYes   Grid Columns
Visible in New RecordYes   * New Record Columns
Visible in Edit RecordYes   * Edit Columns
PHPLens: 4.9.2   Data: 0.02   DB: mysql   adodb: 4.62   Compat: 2   PHP: 5.2.17   OS: Linux
License Type: Enterprise   ID: (Natsoft;John Lim;   Valid Till: Never Expires


What we want is to check if the value in {Country} is a non-breaking space. If it is, we replace the value with "unknown". Otherwise, we display {Country} We have used the ternary conditional operator in PHP for this. Powerlens setting for {country}
     = {Country}=={nbsp} ? "<font color=red>unknown</font>" : {Country} 
The non-breaking space is a special variable in phpLens known as {nbsp}.

Ternary conditional operator
For those of you unfamiliar with the ternary conditional operator, the explanation for this is below:

The ternary conditional operator functions as follows: 
     $first ? $second : $third
If the value of the first subexpression is true (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value. You can read more on this in's online documentation.

Why we can't use "&nbsp;" in Powerlens
When you use phpLens to generate source code, phpLens uses the semi-colon character ";" to separate fields in phpLens properties. Therefore, you cannot enter a semi-colon in Powerlens.
E.g. You cannot enter the following in Powerlens:
     = {Country}==&nbsp; ? "<font color=red>unknown</font>" : {Country} 
As a workaround, phpLens has a variable called {nbsp} to represent "&nbsp;". In the next version of phpLens, we will make available another variable called {semicolon} which will provide you with another way to handle special characters.
email: (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800