Q:

Calling a PHP variable in jQuery

I'am developing a zoom tool in my shopping cart and I am stuck on how to call a PHP variable in a jQuery function.
Here's my code :
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
    zoomrange: [3, 10],
    magnifiersize: [800,300], 
    magnifierpos: 'right',
    cursorshade: true,
    largeimage: "php variable" //we add the directory of the image.
});
});

I need to put 
$src ="images/products/".mysql_result($execute_select_product_query,0,'image1')."

in my function where I put PHP variable.

A:

You have two or three options: if the Javascript is in the php file, you can 
var phpVar = <?php echo $var; ?>;

Otherwise if the Javascript is anywhere at all, you can do:
<input type="hidden" id="phpVar" value="<?php echo $var; ?>">

and then access it as
$('#phpVar').val();

Example 1:
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
    zoomrange: [3, 10],
    magnifiersize: [800,300], 
    magnifierpos: 'right',
    cursorshade: true,
    largeimage: <?php echo $var; ?> //we add the directory of the image.
});
});

Example 2:
Html:  
<input type="hidden" id="phpVar" value="<?php echo $var; ?>">

Javascript
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
    zoomrange: [3, 10],
    magnifiersize: [800,300], 
    magnifierpos: 'right',
    cursorshade: true,
    largeimage: $('#phpVar').val(); //we add the directory of the image.
});
});

A:

Do it like this:
largeimage: "<?php echo $src; ?>"

A:

PHP is server side language and javascript is user side language. Don't mix it. Just use ajax. Or if you have included your script into the PHP file, you can write it to code:
  <?php $srcImg = 'Some value'; ?>
  jQuery(document).ready(function($){
    $('#image1').addimagezoom({ // single image zoom
        zoomrange: [3, 10],
        magnifiersize: [800,300], 
        magnifierpos: 'right',
        cursorshade: true,
        largeimage: "<?php echo $srcImg; ?>" //we add the directory of the image.
    });
  });

Ou use data-attrs
<body data-phpvar="<?php echo $srcImg; ?>">

And in js:
var phpvar = $("body").attr("data-phpvar");

