I am trying to use a getJSON method in jquery to retrieve a dynamic array. I am getting an "illegal" offset error trying to encode my dynamic array. Here is the server side code (I am confident the javascript is correct because when I remove the query it runs fine):
<?php
session_start();
require_once "database.php";
db_connect();
require_once "auth.php";
$current_user = current_user();
include_once("config.php");
$westcoast_id = $_GET['westcoast_id'];
$westcoast_array = array();
$query = "SELECT city, state FROM users GROUP BY city";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if($row['city'] != '' && $row['state'] != '') {
$westcoast_array[$row] = "location:".$row['city'].", ".$row['state'].", stopover:true";
}
}
$data = array($westcoast_id, $westcoast_array);
echo json_encode($data);
?>
The illegal offset is in reference to the line:
$westcoast_array[$row] = "location:".$row['city'].", ".$row['state'].", stopover:true";
I cannot see what the issue is. Thank you for your help!
$rowis an array. How is it supposed to work as a key for another array?