1.11M Members

For loop: syntax error, unexpected T_INC

 
0
 

Hi all,
I have some content which I would like to limit to 9 per page in a table. I haven't done the table code yet, and rather concentrate on trying to get the filter working.

When I try to enter the URL of index.php, where page=2 or without a page number I am getting an error in my for loop.

Parse error: syntax error, unexpected T_INC, expecting ')' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index.php on line 22

<?php
session_start();
if (isset($_GET['page']))
{
	$page=$_GET['page'];
}

else
{
	$page=1;
}
include('functions.php');
get_videos($conn);
gen_header($page);
?>
<div id="container"><?php nav_bar(); ?>
<?php
	$cols=0;
	for($i=1*$page;$page*9;i++)
	{
		echo $i;
	}
?>
</div>
<?php gen_footer(); ?>

The line PHP doesn't like is the for loop but I can't think of another way to limit the content. How do I fix this?

 
0
 

Hi all,
I have some content which I would like to limit to 9 per page in a table. I haven't done the table code yet, and rather concentrate on trying to get the filter working.

When I try to enter the URL of index.php, where page=2 or without a page number I am getting an error in my for loop.

<?php
session_start();
if (isset($_GET['page']))
{
	$page=$_GET['page'];
}

else
{
	$page=1;
}
include('functions.php');
get_videos($conn);
gen_header($page);
?>
<div id="container"><?php nav_bar(); ?>
<?php
	$cols=0;
	for($i=1*$page;$page*9;i++)
	{
		echo $i;
	}
?>
</div>
<?php gen_footer(); ?>

The line PHP doesn't like is the for loop but I can't think of another way to limit the content. How do I fix this?

You have a problem with the for call.

for(initial; while; step)

$page*9 will always be sucessful, alias not stop the loop. You wanna do something like

for($i=0; $i < $page*9; i++)

I'm not completely sure what you're trying to achieve, but the example above will first set $i to zero. Then as long as $i is under $page*9, it will run and increment $i.

 
0
 

Is it correct?

for($i=1*$page;[B]$page*9[/B];i++)
	{
		echo $i;
	}

The bold section should be a condition r8?

 
0
 

I know that the message at the bottom of this page says to let old threads die but I just had to post a reply to this thread.

First off the issue, bsewell, that you're having here is a simple syntax error. You for loop:

for($i=1*$page;$page*9;i++)

should be this:

for($i=1*$page;$page*9;$i++)

Notice the $ on your iterator.

I find it interesting how PHP (and other languages) report their errors in the most cryptic and unmeaningful fashion. T_INC? It seems that a straight up i in a for loop's iterator (or step) is called a T_INC. I can only assume that INC stands for INCREMENT which would make sense, but how'bout this one:

T_PAAMAYIM_NEKUDOTAYIM < What the...?

Turns out that's hebrew for "twice colon" or "double colon". It's an error that you'll encounter while using the scope resolution operator. Doesn't it make you sit there and scratch your head while asking yourself why? Some of these errors might as well say "unexpected T_FINGER_POPPIN_GOOD_TIME". Well, at least it points you to the proper line.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article