943,186 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1394
  • PHP RSS
Jul 4th, 2010
0

For loop: syntax error, unexpected T_INC

Expand Post »
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.

Quote ...
Parse error: syntax error, unexpected T_INC, expecting ')' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index.php on line 22
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. if (isset($_GET['page']))
  4. {
  5. $page=$_GET['page'];
  6. }
  7.  
  8. else
  9. {
  10. $page=1;
  11. }
  12. include('functions.php');
  13. get_videos($conn);
  14. gen_header($page);
  15. ?>
  16. <div id="container"><?php nav_bar(); ?>
  17. <?php
  18. $cols=0;
  19. for($i=1*$page;$page*9;i++)
  20. {
  21. echo $i;
  22. }
  23. ?>
  24. </div>
  25. <?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?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
bsewell is offline Offline
53 posts
since Sep 2009
Jul 4th, 2010
0
Re: For loop: syntax error, unexpected T_INC
Click to Expand / Collapse  Quote originally posted by bsewell ...
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 Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. if (isset($_GET['page']))
  4. {
  5. $page=$_GET['page'];
  6. }
  7.  
  8. else
  9. {
  10. $page=1;
  11. }
  12. include('functions.php');
  13. get_videos($conn);
  14. gen_header($page);
  15. ?>
  16. <div id="container"><?php nav_bar(); ?>
  17. <?php
  18. $cols=0;
  19. for($i=1*$page;$page*9;i++)
  20. {
  21. echo $i;
  22. }
  23. ?>
  24. </div>
  25. <?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.

PHP Syntax (Toggle Plain Text)
  1. for(initial; while; step)

$page*9 will always be sucessful, alias not stop the loop. You wanna do something like
PHP Syntax (Toggle Plain Text)
  1. 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.
Reputation Points: 94
Solved Threads: 26
Posting Whiz
Excizted is offline Offline
309 posts
since Oct 2009
Jul 5th, 2010
0
Re: For loop: syntax error, unexpected T_INC
Is it correct?

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

The bold section should be a condition r8?
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008
Oct 4th, 2011
0
Re: For loop: syntax error, unexpected T_INC
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:
PHP Syntax (Toggle Plain Text)
  1. for($i=1*$page;$page*9;i++)
should be this:
PHP Syntax (Toggle Plain Text)
  1. 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mark_k is offline Offline
1 posts
since Oct 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to get multiple recordset rows passed to ajax?
Next Thread in PHP Forum Timeline: PHP for jobs





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC