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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.