I'm trying to pass a string variable from PHP to Javascript and it is giving me troubles.
I actually pas a number variable as per the code below and it works, but once I introduce (or uncomment) the line var cityname = <?=$city;?>;
in my javascript code then it doesn't work. I believe it has something to do with the type of data because if I introduce a number like Scity = 3
in my PHP then it works.
Thank you
I have the following PHP:
<?php
$get_total_rows = 0;
$city = "London";
$db = pg_connect("$db_host $db_name $db_username $db_password");
$query = "SELECT * FROM table";
$results = pg_query($query);
$get_total_rows = pg_numrows($results);
?>
and I have the following javascript:
<script type="text/javascript">
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
//var cityname = <?=$city;?>;
var total_rows = <?=$get_total_rows;?>;
$('#results').load("autoload_process.php", {'rows':total_rows}, function() {track_load++;}); //load first group