Copy php array to a javascript array

Hope someone can help with this.

I have an array that I got from a database and want to load it into javascript array.  It seems I have tried everything I can think of and have tried to find another question that fits my situation.

Here is a small section of the code:

<?php
echo "<script type=\"text/javascript\" language=\"Javascript\">";
?>

jimageNum[0]=<?php echo $imageNum[0]; ?>;

<?php
echo "</script>";
?>

The 4th line is where I am trying to set the first element of the javascript array to the first element of the php array.  I will be replacing this with a for loop.  Currently this is in the head, but I have tried it in the body.

I'll be thankful for any help on this.

John
JeikoAsked:
Who is Participating?
 
StormyWatersConnect With a Mentor Commented:
That should be fine the way it is... Since it isn't, can you post the View Source of the relevant bit of the page (not the PHP, the actual generated code)

One thing I would do differently is not echo the <script> tags, just put them in the HTML.
0
 
List244Commented:
jimageNum[0]=<?php echo $imageNum[0]; ?>;

Shouldn't that be:

jimageNum[0]=<?php $imageNum[0]; ?>;
0
 
JeikoAuthor Commented:
StormyWaters, you taught me something very valuable.  I looked at the source code and the problem was obvious.  I was missing the quotes.  It should be:

jimageNum[0]="<?php echo $imageNum[0]; ?>";

Thanks a bunch!  Here's a few extra points.
0
 
ThaSmartUnoCommented:
<no-points>

Jeiko are you all set with this question?  It sounds like you are.   I think you forgot to accept the answer

</no-points>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.