Hi, Heshkod! Good evening! Hello!

There is a table with a field of type float . What I just didn’t do was via MySQLi, so that it would take the float value from the database and put the array in my array, and not the string as he likes to do.

I quickly sketched a crutch that interrupts lines in fleets. But I really hope that I can remove it and someone will tell me how to choose a float from MySQL so that I am not ashamed.

Lol Here is a crutch:

 $i = 0; $d = count($regions_db); while($i < $d) { $regions_db[$i][1] = floatval($regions_db[$i][1]); $i++; } 
  • Please attach the crutch to the question) - Palmervan

1 answer 1

I have a feeling that you cannot immediately get a float from the database, although I’m not sure if you need to google it thoroughly:


DB:

 CREATE TABLE t1 (i INT, d1 DECIMAL(9,2), d2 DECIMAL(9,2)); INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00), (2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40), (2, 30.40, 30.40), (3, 37.00, 7.40), (3, -29.60, 0.00), (4, 60.00, 15.40), (4, -10.60, 0.00), (4, -34.00, 0.00), (5, 33.00, 0.00), (5, -25.80, 0.00), (5, 0.00, 7.20), (6, 0.00, 0.00), (6, -51.40, 0.00); SELECT i, SUM(d1) AS a, SUM(d2) AS bFROM t1 GROUP BY i HAVING a <> b; 

Php

 $db = mysql_connect("localhost","root","123456789"); mysql_select_db("test", $db) or die ('Нет такой схемы! : ' . mysql_error()); $sql = "SELECT d1 FROM t1 WHERE i = 1 LIMIT 1"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result, MYSQL_BOTH); $a = $myrow["d1"]; echo $a; echo "</br>"; $resourseType = gettype($myrow["d1"]); print($resourseType); 

Return Type:

 101.40 string