0

I've getting data from a MySQL database (gpio temperature sensor) and storing 1 row into a variable to use with pCharts. This is in php

If i create the variable manually this work

$sensor1c = "24.5,24.5,24.5,24.5,24.5,24.5,24.5,24.5,24.5,24.5,24.5,24.5,";

However if i get the data from the DB and then add it to a variable via a while loop it doesn't work.

$order = "SELECT sensor2c FROM (SELECT * FROM temperature ORDER BY id DESC LIMIT 12) sub ORDER BY id ASC;";
 $result = mysql_query($order); 

 while($data = mysql_fetch_row($result))
 {  
 $sensor1c .= $data[0];
 $sensor1c .= ",";
 }

Does anyone know why the two are different? Also tried with no luck

$sensor1c = (string)$sensor1c;
7
  • Does the query have any results? Commented Jun 8, 2013 at 9:49
  • 1
    You could try with the CONCAT_WS function of MySql to get the result you want without looping. Commented Jun 8, 2013 at 10:02
  • The first thing you should do is add mysql_query($order) or die(mysql_error()); to ensure there is no error in the query. Commented Jun 8, 2013 at 10:02
  • 1
    The second thing you should do is test, if you actually have any results. php.net/manual/en/function.mysql-num-rows.php Commented Jun 8, 2013 at 10:07
  • 1
    @scones mysql_query is procedural code, there is no need for raising an exception in this code here. If there is no data rest can't perform. Let's stick with the scope of the question, not get into a major architecture discussion IMHO Commented Jun 8, 2013 at 10:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.