When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Technical Support Partner Central

4DLOOP

Welcome to the 4D Dynamic Web Page Tutorial! The goal of this tutorial is to help you learn to create dynamic web pages and sites using 4th Dimension. Before you start this tutorial, it is a good idea to have first gone through the previous tutorials in this series - or at least be familiar with the material covered in them. As with the earlier tutorials, this one also assumes you have:

•  4th Dimension 2003 or Higher

•  A text editor (SimpleText, Notepad.exe, etc.)

The focus of this tutorial will be on the 4DLOOP Tag. This tag is used so that elements of a web page can be repeated a number of times. There are three ways to loop: through the elements of an array, for a 4D method that returns True (to continue looping) or False (to end the loop), and through a selection of records from the database.

Create a new 4th Dimension database - call it "LoopDB". Once in the Design environment, go to the Edit menu and choose Properties . Then then select the Web section of the properties dialog.

screenshot

Make changes to the properties to "Publish Database at Startup" and change the Default Home Page to index.shtml. Save the changes you have made to the Properties by clicking the OK button.

The first section of this tutorial will use 4DLOOP with data from an array. To begin, create a new Project Method by going to the Design menu and choosing New Method. Name the new method WSC_LoopFill. Enter the following text into it:

C_LONGINT($iArraySize)

$iArraySize:=Random

If ($iArraySize>1000)
$iArraySize:=$iArraySize/1000
End if

ARRAY TEXT(WSC_at_LoopData;$iArraySize)

C_LONGINT($iIdx)

For ($iIdx;1;$iArraySize)
WSC_at_LoopData{$iIdx}:="Array Element #"+String($iidx)
End for

screenshot

Your WSC_LoopFill should look like the one in the picture above.

Go to the Method menu and choose Method Properties, then select Available through 4DACTION option in the properties dialog.

screenshot

Press the OK button and then close the WSC_LoopFill method before proceeding.

The next step is to go to your text editor and create a new document. Write the following into this new document:

<html>
<head>
<title>4D Loops</title>
</head>
<body>
<!--4DSCRIPT/WSC_LoopFill-->
<!--4DLOOP WSC_at_LoopData-->
<!--4DVAR WSC_at_LoopData{WSC_at_LoopData}-->
<BR>
<!--4DENDLOOP-->
</body>
</html>

Save the document inside the WebFolder as "index.shtml".

Next, go to your web browser and type "127.0.0.1" into the address bar. You should see something like this:

screenshot

 1 2 3 4   Next Step


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D UK 1995-2008 | Change font size: [A] [A] [A] | Print this page