Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2006, 03:32 PM
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with arrays/loops

I am having a problem where my code only works if I fill 14 or less elements of an array(using php and javascript. If I use more than that, it doesnt work.


var a = new Array();
var i = 0;

<?php
$k = 15;
for ($j = 0; $j < $k ; $j++)
{
    ?>
    a[i] = ('<?php echo $rows[$j] ?>');
    i++;
<?php
}
 ?>

when $k is 14 or less, this code works fine, but when it is 15 or more, it doesnt work. I can't for the life of me figure out why this would be a problem.

Any help would be greatly appreciated.
Thanks!
-Josh

 
Old November 7th, 2006, 12:52 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Josh!!

You are getting error becoz of ur $rows have maximum 14 or 15 rows.
when you put $k>15 ,that time your $rows having maximum 15 rows ,while you are looping beyound the max length of $rows(upper bound) , this is the only reason.
so before assiging $k>15 plz check ur upperbound for $rows

Hope this will help you

Cheers :)

vinod
 
Old November 7th, 2006, 03:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think you need to check how many elements $rows contains, if it is less than $k your code will fail. What do you want to do, transfer all the elements from $rows to the client or have a limit on it?

--

Joe (Microsoft MVP - XML)
 
Old November 7th, 2006, 10:27 AM
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the replies... my array has about 25,000 elements in it, I have already checked this.

 
Old November 7th, 2006, 10:29 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Is the error client-side or server-side, and what exactly is it? If the error is client-side does the output have a stray apostrophe in it for example?

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
break for-each loops, or limit amount of loops warhero XSLT 2 July 4th, 2007 02:18 AM
Loops and Arrays - Undefined offset notice dkintheuk Beginning PHP 6 September 12th, 2005 11:38 PM
While loops and For loops in XSLT spencer.clark XSLT 1 August 5th, 2005 09:50 AM
problem with nested loops ptaylor2005 Beginning PHP 4 April 27th, 2005 07:05 PM
Arrays Problem nulogix PHP How-To 2 June 19th, 2004 02:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.