0

I'm selecting some Strings from my SQLite DB and store them in an Array. Now I want to plot the values with the framework "Razorflow". I think it is only possible if the values of the array are floats, am I wrong?

In my DB I'm storing temperature and humidity of 12 different sensor nodes, in this form:

id|temperature|humidity|...|...

1 |     22.50C|  47.50%|...|...
..

I heared something about the floatval()-function, I also heared that this function is not made for objects like Arrays. Is there a simple solution? I'm very new to PHP :-D

1 Answer 1

1

Depends on how you're getting the values back from the database.

id|temperature|humidity|...|...

Sounds like a string to me, so i would first explode it into an array and then iterate the array casting floatval into every element.

What you do after that process depends on you.

EDIT:

If your query is:

$humi = $database->query((SELECT humidity FROM Measurement WHERE topic_hum='WSN9/humi'

You will get back only 1 column (humidity) and 0 or more rows depending on your database. Let's say it's only 1 for now:

$resul = mysql_query($humi,$link);
$rows = mysql_fetch_array($resul);
$myarray = explode("|", $rows["humidity"]);

This should give us an array called myarray containing X elements each with a "single" string part value. So we can iterate over it and parse it. There is also the shorthand "array_map" to iterate over an array using a callback function over each element and returning the value as an array:

$myparsedarray = array_map('floatval', $myarray)

Now you have an array with only float values (and errors maybe, check your data!)

Sign up to request clarification or add additional context in comments.

2 Comments

I tried this command: $humi = $database->query((SELECT humidity FROM Measurement WHERE topic_hum='WSN9/humi' This query gives only one parameter back, this is also wrong. But first i want to convert the array[string] into an array[float]. Thanks for the fast response
it's ok to return only 1 column, because you're only selecting humidity. That string you need to explode it into an array, and then those elements of the array can go into the floatval. Check the links, i'll make a quick edit to put something more specific.

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.