Jump to content

PHP in JavaScript Help


ad_no1

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/186689-php-in-javascript-help/
Share on other sites

<?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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.