I'm currently experimenting with the SQLike query engine from Thomas Frank's website and finding it difficult to grasp the basic concept.
In my project, I have JSON data sourced from my PHP code, which is structured like this:
var placesJSON=<? echo json_encode($arrPlaces) ?>;
Here's an example of the JSON data:
var placesJSON=[{"id":"100","name":"Martinique","type":"CTRY"},{"id":"101","name":"Mauritania","type":"CTRY"},{"id":"102","name":"Mauritius","type":"CTRY"},{"id":"103","name":"Mexico","type":"CTRY"},{"id":"799","name":"Northern Mexico","type":"SUBCTRY"},{"id":"800","name":"Southern Mexico","type":"SUBCTRY"},{"id":"951","name":"Central Mexico","type":"SUBCTRY"},{"id":"104","name":"Micronesia, Federated States","type":"CTRY"},{"id":"105","name":"Moldova","type":"CTRY"}];
According to the documentation on the website, I need to unpack my JSON like this:
var placesData = SQLike.q(
{
Unpack: placesJSON,
Columns: ['id','name','type']
}
)
Following that, I should then query the results using a statement like:
var selectedPlaces = SQLike.q(
{
Select: ['*'],
From: placesData,
OrderBy: ['name','|desc|']
}
To finally display the results in the browser, I would typically use something similar to this:
document.getElementById("myDiv").innerHTML=selectedPlaces[0].name
Despite following these steps, I encounter an error stating "selectedPlaces[0].name is undefined." It seems like I might be overlooking a simple detail. Any advice or hints would be greatly appreciated.