|
|
||||
![]() | ||||
This section describes the syntax which is used to extract elements that have been read into a variable from a database file. The syntax is an extension of the regular variable syntax used by the DI.
For a simple array read-in by the .DBARRAY command,
you would use the syntax varname[row][column], where varname
is the name of the variable defined by the .DBARRAY call, row is
the number of the row you wish to access, and column is the column
number. Row and column numbers start a 0. For instance, this would display the
data in the second column of the first row of the file foo.txt:
<!--.dbarray myvar="foo.txt"--> <!--.echo "The value is $myvar[0][1]"-->
If the row is omitted, then row 0 is assumed. So $myvar[0][5]
and $myvar[5] are equivalent.
For an associative array read-in by the .DBHASH
command, the syntax is varname[row]{keyname}, where varname
is the name of the variable defined by the .DBHASH call, row is
the number of the row you wish to access, and keyname is the name
associated with the column. Keynames are not case-sensitive. For instance, this
would display the data in the Comment column of the first row of
the file foo.txt:
<!--.dbhash myvar="foo.txt"-->
<!--.echo "The value is $myvar[0]{comment}"-->
If the row is omitted, then row 0 is assumed. So $myvar[0]{comment}
and $myvar{comment} are equivalent.
These examples make use of the .DBDUMP command. Please refer to that section for more information.
# This is a comment line path,description /grafx/icons/bPrevious.gif,Previous Button /grafx/icons/bIndex.gif,Index Button /grafx/icons/bNext.gif,Next Button
<!--.dbarray array="dbtest.txt"--> <table cellpadding=2>
<tr>
<td></td>
<td><font color=green>0</font></td>
<td><font color=green>1</font></td>
</tr>
<!--.dbdump dbvar="$array" fmt='<tr>
<td><font color=green>$row</font></td> <td>$array[$row][0]</td> <td>$array[$row][1]</td></tr>'--> </table> <P>The value of $array[1][0] is <!--.echo "$array[1][0]"-->
| 0 | 1 | |
| 0 | path | description |
| 1 | /grafx/icons/bPrevious.gif | Previous Button |
| 2 | /grafx/icons/bIndex.gif | Index Button |
| 3 | /grafx/icons/bNext.gif | Next Button |
The value of $array[1][0] is /grafx/icons/bPrevious.gif
<!--.dbhash hash="dbtest.txt"-->
<table cellpadding=2>
<!--.dbdump dbvar="$hash" fmt='<tr>
<td><font color=green>$row</font></td>
<td>$hash[$row]{path}</td>
<td>$hash[$row]{description}</td>
</tr>'-->
</table>
<P>The value of $hash[1]{description} is <!--.echo "$hash[1]{description}"-->
| 0 | /grafx/icons/bPrevious.gif | Previous Button |
| 1 | /grafx/icons/bIndex.gif | Index Button |
| 2 | /grafx/icons/bNext.gif | Next Button |
The value of $hash[1]{description} is Index Button
<!--.dbdump dbvar="$hash" fmt='
<img src="$hash[$row]{path}" alt="$hash[$row]{description}">'-->
You can also create and modify hashes and arrays using the .SET
command:
<!--. set myarray[0]="zero"; set myarray[1]="one"; set myarray[3]="three"; echo "<P>$&join(' | ','$myarray')"; set myhash{1}="value1"; set myhash{2}="value2"; set myhash{3}="value3"; echo "<FORM>Here's a popup: $&selectlist(choice1,2,hash='$myhash') </FORM>"; -->zero | one | | three
Notice how an empty slot was automatically created in the array at index [2]
when index [3] was assigned.
Home | MyMHC | Web Email | Directories | SiteMap | Search | Help
Admission |
Academics |
Campus Life |
Athletics Copyright © 2001 Mount Holyoke College. This page created by the OIS Operations Group and maintained by Webmaster. Last modified on November 2, 2001. |