Jump to content

Help adding another loop to existing for loop


AshleyQuick

Recommended Posts

The $lvNum variable works for the first table row but continues to display f4 in subsequent rows.  I assume it's not incrementing because I'm not integrating it into the existing for loop properly (still a novice obviously :)  Can someone help and maybe explain briefly how it works?

 

<?php
for($i=2; $i<=$numberofrecipients; $i++) {
$value = isset($_POST['to'][$i]) ? $_POST['to'][$i] : '';
$lvNum = 3;
{
?>
<tr>
<td class="formtext3"><?php echo $i ?>.</td>
<td><input id="f<?=++$lvNum?>" type="text" name="to[<?php echo $i ?>]" value="<?php echo $value ?>">
<script type="text/javascript">
	var f<?=$lvNum?> = new LiveValidation('f<?=$lvNum?>');
	f<?=$lvNum?>.add(Validate.Email );
</script>
</td>
</tr>
<?
}
}
?>

what is $lvNum supposed to be? 1 greater then $1? why not use:

<?php
for($i=2; $i<=$numberofrecipients; $i++) {
  $value = isset($_POST['to'][$i]) ? $_POST['to'][$i] : '';
?>
<tr>
  <td class="formtext3"><?php echo $i ?>.</td>
  <td><input id="f<?php echo $i + 1; ?>" type="text" name="to[<?php echo $i ?>]" value="<?php echo $value ?>">
    <script type="text/javascript">
      var f<?php echo $i + 1; ?> = new LiveValidation('f<?php echo $i + 1; ?>');
      f<?php echo $i + 1; ?>.add(Validate.Email );
    </script>
  </td>
</tr>
<?php
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.