## ## Document History ## ## Created (peeje01) ## 27-Apr-1999 (peeje01) ## Change include file name from -h.html to _h.html ## 02-Apr-2004 (fanra01) ## Bug 112091 ## Editorial changes from griel02. ## Using the IF Statement

Using the IF statement

In the previous example, when the information in the table was exhausted, the page displayed the column headers and no rows. If you haven't seen this, you might like to try it now.
We would prefer the user to be presented with a way of resetting the cursor to the beginning of the result set again so as to be able to return to the beginning.
We choose to do this only when the number of rows returned is not 5 (the requested number). When there are more than 5 rows available the ICE server will always return 5 and set ii_rowcount accordingly. When there are fewer than 5 rows to return ii_rowcount will be set to the appropriate value. We can, therefore, test the inequality of ii_rowcount with 5.

The select statement is as before but now we include the test. If we receive fewer than 5 rows (ii_rowcount != 5) we insert the HTML to visit another page which is a facsimilie of this page but commits the transaction before running exactly the same query. This allows us to restart from the beginning of the result set.

Our solution appears below:

File: play_allWrap.html

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>
<FORM ACTION="/ice-bin/oiice.dll/playgroup/plays[play_allWrap.html]"
	METHOD="POST">

<!-- #ICE REPEAT 
          DATABASE = `icetutor` 
          SQL=`select * from plays` 
          TRANSACTION=`Complete` 
          CURSOR=`Works` 
          ROWS=`5` 
          TYPE=`TABLE`
-->

<!-- #ICE IF ( `:ii_rowcount` != `5` )
	THEN=`<p>
	<b>
	<a href="/ice-bin/oiice.dll/playgroup/plays[play_allWrapSub.html]">
        Re-start from the beginning
        </a></b><p>`
--> 

<!-- #ICE DECLARE=`session.e_playTxn=Complete` -->
<!-- #ICE DECLARE=`session.e_playTxnCommitted=FALSE` -->
<p>
<INPUT TYPE="submit" NAME="More" VALUE="More" >
<!-- #ICE REPEAT INCLUDE=`plays[play_SessionControl_h.html]` -->
</FORM>
</body>
</html>

The interesting part of the file is:

<!-- #ICE IF ( `:ii_rowcount` != `5` )
	THEN=`<p>
	<b>
	<a href="/ice-bin/oiice.dll/playgroup/plays[play_allWrapSub.html]">
        Re-start from the beginning
        </a></b><p>`
--> 
If the number of rows returned is not 5 then it must be less than 5. We must test the inequality here because the if statement performs string comparisons. If the number of rows is less than 5 (we have reached the end of the result set), we wish to give the user the oppertunity to visit a 'reset' page. The then branch of the if inserts the required link.

To start again, the first thing we must do is to commit the previous transaction:

<!-- #ICE COMMIT=`:e_playTxn` -->

We then start exactly the same transaction again, giving the illusion that the user has visited the same file. Notice that the action on pressing the more button is to return to the original file.

Question: Could this functionality be achieved in one file? If not, why not?

File: play_allWrapSub.html

<html>
<head>
<title>Shakespeare's Plays</title>
</head>
<body>

<!-- #ICE COMMIT=`:e_playTxn` -->

<!-- #ICE 
          DATABASE = `icetutor` 
          SQL=`select * from plays` 
          TRANSACTION=`Complete` 
          CURSOR=`Works` 
          ROWS=`5` 
          TYPE=`TABLE`
-->

<!-- #ICE DECLARE=`session.e_playTxn=Complete` -->
<!-- #ICE DECLARE=`session.e_playTxnCommitted=FALSE` -->

<FORM ACTION="/ice-bin/oiice.dll/playgroup/plays[play_allWrap.html]"
	METHOD="POST">
<INPUT TYPE="submit" NAME="More" VALUE="More" >
</FORM>

<!-- #ICE REPEAT INCLUDE=`plays[play_SessionControl_h.html]` -->
</body>
</html>
The next page shows how the Web Deployment Option can generate the tags needed for a combo or list box.