Q:

php not workng in javascript

sub1 is not working it is being called on the click of the button can use please help me 
how can i get values from php variables to javascript variable,
<html>
<head>
<script language="javascript">

 function sub1()
 {
     var x=<?php echo $present; ? >;
     var y=<?php echo $min; ? >;
     var z=<?php echo $max; ? >;
     change(x,y,z);

     alert("hello");
     change();
  }

  function change(var no,var min,var max)
  {
       alert("hello1");
       var x=document.getElementById("show");
       x.src='<?php
           if($con==true)
           {
               $cmd="select * from showcase where item_no=3";
               if($res=$con->query($cmd))
               {
                    if($res->num_rows>0)
                    {
                        while($rw=$res->fetch_array())
                        {
                             echo "$rw[1]";
                        }
                    }
                    else
                    {
                        echo "no record found";
                    }
               }
               else
               {
                   echo "query problem";
               }
           }
       ? >'; 
   }
</script>
</head>
</html>

i am working on a slider which changes pic on the click of the button

A:

Edit based on suggestion from @DCoder:
You should use json_encode() which is able to output arrays, objects and complex strings safely:
var x=<?php echo json_encode($present); ? >;

You could also just wrap the PHP output in quotes, but you would have to have full control over the contents of the variable.  If you know that the variable is always going to be a number, a boolean value or a simple string without quotes, that should be safe too.