Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 









Oracle Database Tips by Donald Burleson


While Statement

The syntax of the while statement is extremely simple: 

    while ( expression ) { statement block; }
Note the following example:
    while ( $i>0 ) {
            $FACT *= $i;

Here is a PHP script that computes 5!  The "factorial" of the number N is equal to product of all numbers from 1 to N.  Written mathematically, N!=1*2*3*...*N. For the number 5, the formula reads: 5!=1*2*3*4*5=120.

The following example shows this in script form:

Example 3:

    $ cat example3.php
    while ( $i>0 ) {
            $FACT *= $i;
    print "Factorial:$FACT\n";
    $ ./example3.php

Like the if statement, the while statement has a form that allows for easy embedding into HTML:

<?php while (expression): ?>
<?php endwhile; ?>

For Statement

The syntax of the for statement is completely analogous to the syntax of the same statement found in other programming languages:

for(begin expression; end expression; step expression)
    { statement block; }
or, alternatively, for easier embedding into HTML: 

<?php for(begin expr; end expr; step expr): ?>
<?php endfor; ?>

The begin expression is evaluated at the beginning of the loop and is usually used for assigning values to the variables used in loop. The end expression is evaluated at the beginning of each loop iteration. When the end expression evaluates to FALSE, the loop stops. The step expression is evaluated once per iteration and is typically used to increase or decrease the value of the loop iterator. Sounds very complicated, doesn't it?

The following example makes it appear much simpler:

Example 4:

    $ cat  example4.php
    for( $i=1; $i<= 5; $i++) {
        $FACT *= $i;
       print "Factorial:$FACT\n";
      $ ./example4.php

This example is a bit more complicated, illustrating the alternative syntax for the for statement:

Example 5:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
 <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1st July 2004), see">
  <title>Example 5</title>
     $FACT *=$i; ?>Factorial=<?=$FACT?>
  <?php endfor; ?>
  Final factorial=<?=$FACT?>

The output produced by a web browser looks like the following: 

This script contains several elements worth discussing in further detail. These elements are as follows:

  • The way it is produced (using the "tidy" program).

  • <?=$FACT?> syntax for displaying the value of the $FACT variable.

  • How PHP is embedded in a HTML file.

First, how is the script produced? The script is produced by using the program for pretty-printing and checkup of HTML documents called "tidy". More information about the tidy program can found on

The following information is helpful for the tidy program:

$ tidy -help
tidy [option...] [file...] [option...] [file...]
Utility to clean up and pretty print HTML/XHTML/XML

Options for HTML Tidy for Linux/x86 released on 1st July 2004:

File manipulation

  -out or -o <file> specify the output markup file
  -config <file>    set configuration options from the specified <file>
  -f      <file>    write errors to the specified <file>
  -modify or -m     modify the original input files

Processing directives

  -indent  or -i    indent element content
  -wrap <column>    wrap text at the specified <column> (default is 68)
  -upper   or -u    force tags to upper case (default is lower case)
  -clean   or -c    replace FONT, NOBR and CENTER tags by CSS
  -bare    or -b    strip out smart quotes and em dashes, etc.
  -numeric or -n    output numeric rather than named entities
  -errors  or -e    only show errors
  -quiet   or -q    suppress nonessential output
  -omit             omit optional end tags
  -xml              specify the input is well formed XML
  -asxml            convert HTML to well formed XHTML
  -asxhtml          convert HTML to well formed XHTML
  -ashtml           force XHTML to well formed HTML
  -access <level>   do additional accessibility checks (<level> =
1, 2, 3)

Character encodings

  -raw              output values above 127 without conversion to entities
  -ascii            use US-ASCII for output, ISO-8859-1 for input
  -latin0           use US-ASCII for output, ISO-8859-1 for input
  -latin1           use ISO-8859-1 for both input and output
  -iso2022          use ISO-2022 for both input and output
  -utf8             use UTF-8 for both input and output
  -mac              use MacRoman for input, US-ASCII for output
  -win1252          use Windows-1252 for input, US-ASCII for
  -ibm858           use IBM-858 (CP850+Euro) for input, US-ASCII for output
  -utf16le          use UTF-16LE for both input and output
  -utf16be          use UTF-16BE for both input and output
  -utf16            use UTF-16 for both input and output
  -big5             use Big5 for both input and output
  -shiftjis         use Shift_JIS for both input and output
  -language <lang>  set the two-letter language code <lang> (for future use)  


  -version  or -v   show the version of Tidy
  -help, -h or -?   list the command line options
  -help-config      list all configuration options
  -show-config      list the current configuration settings

Use --blah blarg for any configuration option "blah" with argument "blarg"

Input/Output default to stdin/stdout respectively.  Single letter options apart from -f may be combined as in: 

tidy -f errs.txt -imu foo.html

For further info on HTML see

The script is produced by executing the following command from the script called example.php:

tidy -i example.php>example5.php

The example.php script resembles the following:

$ cat example.php
<title>Example 5</title>
   $FACT *=$i; ?>
<?php endfor; ?>
   <HR><BR>Final factorial=<?=$FACT?><BR>

The "-i" option is used for indentation. This option is sufficient for the vast majority of scripts. The style of the HTML documents produced is a matter of personal expression and the reader is encouraged to experiment until the aesthetically satisfactory result is reached.

The <?=$FACT?> syntax used in the script should also be noted.  This syntax is an abbreviation for the following: <?php echo $FACT ?>  and works only if the PHP interpreter recognizes the so called "short open tags".  There is a parameter in the php.ini file called the "short_open_tag".  The following snippet is from the php.ini file which defines the parameter, together with the comments from the PHP creators advising that the short tags be turned off:

; Allow the <? tag.  Otherwise, only <?php and <script> tags
; are recognized.
; NOTE: Using short tags should be avoided when developing
; applications or
; libraries that are meant for redistribution, or deployment
; on PHP servers which are not under your control, because
; short tags may not be supported on the target server. For
; portable, redistributable code,  be sure not to use short
; tags.
short_open_tag = On

As an Oracle DBA I don't have very many chances to write scripts for the servers that aren't under my control. In addition to that, I usually favor brevity, so I do use short tags wherever I can. 

This book aims to present ways to use Oracle RDBMSin conjunction with PHP.  Coming from a long term Oracle DBA, recommendations and advices in this book are somewhat slanted toward the DBA-centric view of the world. Developers may possess a somewhat different perspective. Thus, every piece of advice that should be taken as a discussion point rather than true advice will be noted. This is one such situation.

The last point in this section is about embedding PHP elements into HTML files.  There is no excuse for using "print" and "echo" commands to print HTML tags. PHP scripts are meant to be embedded into HTML documents.

See code depot for complete scripts

This is an excerpt from the book Easy Oracle PHP.  You can get it for more than 30% by buying it directly from the publisher and get instant HTML-DB scripts from the code depot:

Easy Oracle PHP
Create Dynamic Web Pages with Oracle Data

Includes online HTML-DB code depot

Buy it now for 30% off - Only $19.95

HTML-DB support:

For HTML-DB development support just call to gat an Oracle Certified professional for all HTML-DB development projects.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.