Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Javascript with PHP code in .tpl file Rate Topic   - - - - -

 
  • ursula1000
  • Junior Member
  • Members
  • Join Date: 04-Dec 06
  • 1 posts

Posted 04 December 2006 - 02:41 PM #1

How to include in template file javascript code like this:

<script language="JavaScript" type="text/javascript">
var i=0;
galleryConfig.images = new Array();
<?php
$product_id = $_GET['product_id'];
$link = mysql_connect("xxxx","xxxx","xxxx");
mysql_select_db("xxxx");
$query = "SELECT * FROM cscart_product_images_links WHERE product_id =" . $product_id . "";
$results = mysql_query($query);
while($row = mysql_fetch_assoc($results)) {?>
galleryConfig.images[i] = {full:"image.php?object_type=product&image_id=<?php echo $row['image_id']; ?>", thumb: "image.php?object_type=product&image_id=<?php echo $row['image_id']; ?>" };
i++;
<?php } ?>
</script>


 
  • gpmichal
  • Member
  • Members
  • Join Date: 27-Sep 08
  • 34 posts

Posted 27 April 2011 - 05:47 PM #2

I could be wrong, but I think PHP code will only work in a file with a .php extension.

 
  • S-Combs
  • Senior Member
  • Members
  • Join Date: 09-Nov 06
  • 692 posts

Posted 27 April 2011 - 05:55 PM #3

Try it like this

{literal}
<script language="JavaScript" type="text/javascript">
var i=0;
galleryConfig.images = new Array();
{php}
$product_id = $_GET['product_id'];
$link = mysql_connect("xxxx","xxxx","xxxx");
mysql_select_db("xxxx");
$query = "SELECT * FROM cscart_product_images_links WHERE product_id =" . $product_id . "";
$results = mysql_query($query);
while($row = mysql_fetch_assoc($results)) {{/php}

galleryConfig.images[i] = {full:"image.php?object_type=product&image_id={php} echo $row['image_id']; {/php}
", thumb: "image.php?object_type=product&image_id={php} echo $row['image_id'];{/php}" };
i++;
{php} } {/php}
</script>
{/literal}

Secure Cart Hosting
[CS-Cart Optimized Solutions and Server Management]