Hi Everyone:
I can't get a loop to display correctly.
The loop works and displays data, but not
in precisely the way I would like.
Here's the scoop on the loop:
page1.php has a form text field that collects the number of chapters in a book as "booknumchaps"
page2.php asks for the chapter title for each chapter.
I want the loop on page2.php to provide the same amount of
text boxes as in the page1.php variable "booknumchaps"
I can get that to work with this (as it appears on page2.php):
<?
for ($i=0; $i<$book_booknumchaps; $i++)
echo "\n<tr>
<td>
Chapter $i
</td>
</tr>";
// there's a text box here that collects the chapter title
?>
If a user enters "4" in the booknumchaps text field on page1.php,
I will get the four text boxes on page2.php, but they are numbered
Chapter 0
Chapter 1
Chapter 2
Chapter 3
I have tried absolutely everything I can think of to add 1 to the output so that the chapters are numbered
Chapter 1
Chapter 2
Chapter 3
Chapter 4
But nothing seems to work.
Here are some of the things I've tried (none of them give me the output I want):
changing the loop to this:
for ($i=0; $i<$book_numofchapters+1; $i++)
adding a variable before the loop:
<?
$n = $i + 1;
for ($i=0; $i<$book_numofchapters; $i++)
echo "\n<tr>
<td>
Chapter $n
</td>
</tr>";
?>
changing the echo to:
echo "\n<tr>
<td>
Chapter $n"+1"
</td>
</tr>";
or changing the echo to:
echo "\n<tr>
<td>
Chapter $n"+1";
</td>
</tr>";
or changing the echo to:
echo "\n<tr>
<td>
Chapter $n["+1"];
</td>
</tr>";
I've tried probably four or five other iterations of quotation marks, etc., in different places, but nothing gives me the out put I want.
Any help would be greatly appreciated.
Thanks!