ad_no1 Posted December 30, 2009 Share Posted December 30, 2009 Hi I'm creating a dynamic page where information is coming from a MySQL database and put in the correct place but I have hit a brick wall where I want to insert PHP code inside JavaScript. The JavaScript code is part of a picture gallery. Below is the code: imagearray: [ ["hydrogen/image/hydrogen_electron_shell.gif", "", "_new", "while ($row = mysql_fetch_array($image_title)){echo $row['image_1_title'];}"] ], When previewing the website, I am getting a syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Is this possible or is there a more efficient way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/186689-php-in-javascript-help/ Share on other sites More sharing options...
oni-kun Posted December 30, 2009 Share Posted December 30, 2009 Is that the actual code you're using? Or are you var_dump()ing the array? Post all the relevant code that you use, and mark the line where you get the error, and don't forget to place it in tags. Quote Link to comment https://forums.phpfreaks.com/topic/186689-php-in-javascript-help/#findComment-985942 Share on other sites More sharing options...
ad_no1 Posted December 30, 2009 Author Share Posted December 30, 2009 <?php $element = 1; //$_POST['element']; echo <<<_END <html><head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="simplegallery.js"></script> <script type="text/javascript"> var mygallery2=new simpleGallery({ wrapperid: "simplegallery1", dimensions: [400, 265], imagearray: [["hydrogen/image/hydrogen_electron_shell.gif", "", "_new", "[code=php:0]while ($row = mysql_fetch_array($image_title)){echo $row['image_1_title'];} "]], // error on line autoplay: [false, 2500, 2], persist: true, fadeduration: 1000, oninit:function(){}, onslide:function(curslide, i){}}) </script></head> <title>Form Test</title><body> _END; require_once 'conn.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); mysql_select_db($db_database); $image1 = mysql_query ("SELECT image_1 FROM elements WHERE element_id = " .$element); $image1_title = mysql_query ("SELECT image_1_title FROM elements WHERE element_id = " .$element); mysql_close($db_server); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/186689-php-in-javascript-help/#findComment-985958 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.