I am not sure how I should use the data passed along with an ajax call in the PHP script. Specifically, here is the code for the ajax call:
if (node_selected!=0 & node_selected!=null){
$.ajax({
type: "POST",
url: "php/fetch_sensors.php",
data: node_selected,
dataType:'json',
success: function( options ){
...
}
});
}
'node_selected' is an integer variable.
And here is the PHP script (the fetch_sensors.php):
$query = "SELECT SensorID,Variable FROM sensors WHERE SensorID IN (SELECT SensorID FROM nodesensors WHERE NodeID=node_selected)";
$result = mysql_query($query, $con) or die('query not made');
while ($row = mysql_fetch_assoc($result)) {
$sensors[] = $row;
}
echo json_encode($sensors);
If I replace 'NodeID=node_selected' with 'NodeID=2' (2 is just an example) everything works fine. So, I figure that I don't use correctly the 'node_selected'. Any ideas?
Thanks a lot!
'node_selected' is an integer variable