We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,680 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

For loop: syntax error, unexpected T_INC

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?

4
Contributors
3
Replies
1 Year
Discussion Span
1 Year Ago
Last Updated
5
Views
bsewell
Junior Poster in Training
70 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

Excizted
Posting Whiz
309 posts since Oct 2009
Reputation Points: 94
Solved Threads: 27
Skill Endorsements: 0

Is it correct?

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

The bold section should be a condition r8?

rajarajan07
Nearly a Posting Virtuoso
1,450 posts since May 2008
Reputation Points: 167
Solved Threads: 241
Skill Endorsements: 1

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.

Mark_k
Newbie Poster
3 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0624 seconds using 2.7MB