i am trying to run the following php code:
$con = mysql_connect("localhost", "root", "") or die('connection not made');
$db = mysql_select_db('name', $con) or die('db not selected');
$query1 = "SELECT * FROM nodesensors WHERE NodeID=2";
$result1 = mysql_query($query1, $con);
$sensorids = mysql_fetch_array($result1);
$query2 = "SELECT SensorID, Variable FROM sensors WHERE SensorID IN($sensorids)";
$result2 = mysql_query($query2, $con) or die('query not made');
$sensors = mysql_fetch_array($result2);
echo $sensors;
where i want to get only those sensors that have a SensorID, which is also a value in the 'sensorids' array. When i run the code i get the following:
Notice: Array to string conversion in C:\...\test.php on line 10
query not made
When i remove the "$" as follows:
$query2 = "SELECT SensorID, Variable FROM sensors WHERE SensorID IN(sensorids)";
the notice goes away, but still, the query is not made.
Is there any problem with the format of the 'sensorids' array?
Also, is 'echo' the right way to present the array or should i use another method?
Thanks a lot!