Jump to content

Increase Variable Number in Loop ex:($var1, $var2, $var3)


phoenixx

Recommended Posts

I'm trying to increase the variables $schedulemonth, $scheduledate, $scheduleyear in each loop so that they look like $schedulemonth1, $schedulemonth2, $schedulemonth3, etc... for each of them.  I've tried several options and know I'm on the right track, but no go.

 

The customer will choose how many payments and the script below will loop that many times - I have that part working - but the calendar I'm using with the variables above is the issue.

 

Here's the code I'm using.

while ($balance > 0){

	if ($balance>$monthlypayment){
			$myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear);
			//output the calendar
			$myCalendar->writeScript();	
			echo "   ";
				echo "<input type=\"text\" name=\"payment" . $monthlypayment . "\" value=\"" . $monthlypayment . "\">\n";
				$paymenttotal=($monthlypayment+$paymenttotal);
				$balance=round(($invoicetotal-$paymenttotal),2);
				echo "   Balance: $balance\n";
			$schedulemonth++;
			if ($schedulemonth==13){
				$schedulemonth=1;
				$scheduleyear=($scheduleyear+1);
			}
	echo "<br>\n";
		}
		if ($balance<$monthlypayment||$balance==$monthlypayment){
			$myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear);
			//output the calendar
			$myCalendar->writeScript();	
			echo "   ";
				echo "<input type=\"text\" name=\"payment" . $paymentnumber . "\" value=\"" . $balance . "\">\n";
				$paymenttotal=($balance+$paymenttotal);
				$balance=round(($invoicetotal-$paymenttotal),2);
				echo "   Balance: $balance\n";
			$schedulemonth++;
			if ($schedulemonth==13){
				$schedulemonth=1;
				$scheduleyear=($scheduleyear+1);
			}
	echo "<br>\n";
		}
}

 

Additionally it needs to  pick up each of these variables on the next page  the variables are part of hidden fields in an form later in the page.  So my question is actually 3 fold.

1. How do I increase the variable count in the loop above.

2. How do I put the <input type="hidden".......> in the form so that it loops through and catches the increasing variables

3. How do I loop through on the insertion page after the form is submitted to catch how many inserts to the database are needed.

 

This one has me bent over.

Link to comment
Share on other sites

You would be much better off using arrays instead of variable variables, allot more efficient.

 

I never got on with, nor understood the point of variable vars. IS there a point to them, can they be used in the correct context, are they beneficial?

 

Yes, arrays ARE invaluable. Just adding my 10p there.

 

Rw

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.