Snape Posted October 23, 2011 Share Posted October 23, 2011 Hello. Hope you can help me. I have this code: <?php $test=array("5","6,","8,"); $senteces=array(); $news=array(); $con = sasql_connect("some;some;some;some;some"); if (!$con) { echo "sasql_connect failed\n"; } else { echo "connect succed"; } $sel="SELECT text, sentence FROM vijesti WHERE check_news = 1"; $upit = sasql_query($con,$sel); while ($row=sasql_fetch_array($upit)) { $news[]=$row['text']; $sentences[]=$row['sentence']; } sasql_close($con); ?> <?php $i=0; // here i'm echoing PHP news and senteces array values. this is fine. do { echo $news[$i]; echo $sentences[$i]."</br>"; $i=$i+1; } while($i<count($vijesti)); ?> <html> <head> <script type="text/javascript"> function ispis() { var jsArray = ["<?php echo join("\", \"", $news); ?>"]; //this is wrong, i cant get why,??? with this code it is fine var jsArray = ["<?php echo join("\", \"", $test); ?>"]; alert(jsArray[0]); //alerting first element... } </script> </head> <body> <input type="button" value="Alert" onclick="ispis()"> //some html for testing </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249638-php-array-to-js-array/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.