/    Sign up×
Community /Pin to ProfileBookmark

Please 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.

Any help would be greatly appreciated.
Thanks!
-Josh

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyNov 06.2006 — why don't you do a foreach?
Copy linkTweet thisAlerts:
@jfernauthorNov 06.2006 — The Little Guy,

Thanks, I tried using a foreach, but got the same outcome =(
Copy linkTweet thisAlerts:
@theRamonesNov 07.2006 — untested :

<?php

$k = 15;

for ($j = 0; $j < $k ; $j++)

{

?>

i = <?=$j?>;

a[i] = ('<?php echo $rows[$j] ?>');

<?php

}

?>
×

Success!

Help @jfern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...