[FX.php List] Creating Reusable Code
Andy Gaunt
andy at fmpug.com
Sat Sep 9 10:34:20 MDT 2006
Jonathon,
Try the following.
<?php
echo '<tr class="ver10" valign="top">';
$total = 10;
$counter = 1;
while ($counter <= $total) {
echo '<td><input name="'.$term.$ counter.'" type="text"
id="'.$term.$ counter.'" size="'.$termwidth.$ counter.'"></td>';
$ counter ++;
}
echo '</tr>';
?>
Changing the value for the while statement will let you increase or decrease
the number of cells created.
Another option is a 'for' loop
$total = 20;
echo '<tr class="ver10" valign="top">';
for($counter=0; $counter < $total; $counter++) {
echo '<td><input name="'.$term.$counter.'" type="text"
id="'.$term.$counter.'" size="'.$termwidth.$counter.'"></td>';
}
echo '</tr>';
Andy Gaunt
Office: 321.206.3658
Mobile: 407.810.4722
andy at fmpug.com
http://www.fmpug.com
2006 FileMaker Excellence Award Winner
Recipient of FileMaker's 2005 "Mad Dog" Public Relations Award
For chapter locations, dates & times please visit the website at
http://www.fmpug.com If you can make it to a meeting, please RSVP at
http://www.fmpug.com/rsvp.php
-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Jonathan Schwartz
Sent: Saturday, September 09, 2006 11:54 AM
To: FX.php Discussion List
Subject: [FX.php List] Creating Reusable Code
Hi Folks,
I'm attempting to get more efficient with scripting.
My first step was to remove hard-code field names from my favorite
search and display script, creating variables for each field and
defining those variables at the top of the document. This works
great. Now, I can re-purpose the script for another db and layout by
just changing the field variables at the top of the page, instead of
ripping apart the entire document.
The second area I'm looking at is to reduce the repetition of
repetitive code (example below actually has 10+ iterations) and use
an iterative loop to accomplish the same, counting from 1 to n lines.
Is that possible/reasonable/reccomended/etc?
Thanks
Jonathan
<tr class="ver10" valign="top">
<td><input name="<? echo $term1; ?>" type="text" id="<? echo
$term1; ?>" size="<? echo $termwidth1; ?>"></td>
<td><input name="<? echo $term2; ?>" type="text" id="<? echo
$term2; ?>" size="<? echo $termwidth2; ?>"></td>
<td><input name="<? echo $term3; ?>" type="text" id="<? echo
$term3; ?>" size="<? echo $termwidth3; ?>"></td>
--
Jonathan Schwartz
FileMaker 8 Certified Developer
Associate Member, FileMaker Solutions Alliance
Schwartz & Company
jonathan at eschwartz.com
http://www.eschwartz.com
http://www.exit445.com
415-381-1852
_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list