Have an odd one for you...
I have a dashboard which displays data from a BMS system, it's written in php, html & css with a splattering of java. I have a MySQL query which I can run in MySQL workbench and it returns the expected result. However when I run the same MySQLi query from my webpage no value is returned? The Table is called:- currentValues and the column with the BMS values in it is called:- currentValue, again out of my control [designed by BMS vendor] referencePath is the column with the BMS endpoints in. The database is selected as part of my $conn string...
Here is my MySQL Workbench query:
SELECT SUBSTRING(currentValue, 1, 3) FROM currentValues WHERE referencePath LIKE '%CO2_Level'
Here is my webpage query:
$sql = "SELECT SUBSTRING(currentValue, 1, 3) FROM currentValues WHERE referencePath LIKE '%CO2_Level'";
$result = $conn->query($sql);
$row = mysql_fetch_object($result);
echo "<h1>" . $row . " PPM</h1>";
The reason I am using SUBSTRING is because the value has 4 decimal places and the column is a VARCHAR [which I can't change], I only want the whole number [well, technically it's a string].
I have also tried the alternative to SUBSTRING -> LEFT(currentValue, 3) but this behaves in the same way? Any suggestions would be greatly received!!!
EDIT...
However if I use the query without the SUBSTRING()
$sql = "SELECT * FROM currentValues WHERE referencePath LIKE '%CO2_Level'";
$result = $conn->query($sql);
$row = mysql_fetch_object($result);
echo "<h1>" . $row["currentValue"] . " PPM</h1>";
All works as expected except I have a silly value in my Dashboard like 627.1498 PPM
WORKAROUND
This question was closed as DUPLICATE to an unrelated question so I am unable to post this as the answer. Although really it's a workaround not the answer for the above, but may be helpful for others, I simply used the php operator ROUND to round the value returned in my MySql query.
echo "<h1>" . round($row["currentValue"]) . "PPM</h1>";