Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2006, 08:01 PM   PM User | #1
jfern
New to the CF scene

 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jfern is an unknown quantity at this point
need help with weird array/loop problem

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.


**I have a php array called $rows and want my javascript array a to have the same data as $rows**

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.

I have also tried using a foreach statement and that doesn't work either. I know my php array $rows is filled with about 25,000 elements.

Any help would be greatly appreciated.
Thanks!
-Josh
jfern is offline   Reply With Quote
Old 11-07-2006, 02:13 PM   PM User | #2
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
hmmm, well, what's the error you're getting? Are you getting proper javascript outputted in your HTML source? Are you getting a PHP error or a JavaScript error.

Need more info.

Also, skip that 'i' variable in javascript and just array.push: (and use [ code] tags when posting)
Code:
var a = new Array();

<?php
$k = 15;
for ($j = 0; $j < $k ; $j++)
{
?>
a.push('<?php echo $rows[$j] ?>');
<?php
}
?>
Beagle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:56 AM.


Advertisement
Log in to turn off these ads.