/    Sign up×
Community /Pin to ProfileBookmark

weird problem with arrays/loops, please help!

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
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@semi-sentientNov 06.2006 — Are you sure you have more than 14 elements in the $rows array? You might consider putting an extra condition in your [b]for[/b] loop that also checks the array length just to be sure.
Copy linkTweet thisAlerts:
@jfernauthorNov 06.2006 — Semi-sentient. I do have more than 14 elements, I have about 25,000. I also tried using a different set of data for $rows(it is elements pulled from a mySQL database), which had about 10,000 entries, and still could not have the code work when greater than 14.
Copy linkTweet thisAlerts:
@ohlaphNov 06.2006 — You need to add an else statement to do something if it's 15 or over. If 15 is the largest you will get, then you could do:
[CODE]for ($j = 0; $j <= $k ; $j++)[/CODE] adding a = or change $k to 16. Either case, you should have an else statement.
Copy linkTweet thisAlerts:
@jfernauthorNov 06.2006 — You need to add an else statement to do something if it's 15 or over. If 15 is the largest you will get, then you could do:
[CODE]for ($j = 0; $j <= $k ; $j++)[/CODE] adding a = or change $k to 16. Either case, you should have an else statement.[/QUOTE]



I do not know what you mean, How could I use an else statement without an if? I have it as 15 in my code just because that is what it stopped working at. If i make $k=20, or just do $j <=20,(or any number aboce 14)it still does not work.
×

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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...