I'm trying to convert a data from string to float and insert it to MYSQL database. $data variable is a string. Here's my SQL query:
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
stockcode VARCHAR(8) NOT NULL,
lastprice FLOAT NOT NULL,
open FLOAT NOT NULL,
close FLOAT NOT NULL,
low FLOAT NOT NULL,
high FLOAT NOT NULL
)";
$rows = $table->getElementsByTagName("tr");
$i = 0;
foreach ($rows as $row) {
if ($i++ < 1) {
continue;
}
$a = array();
$cells = $row->getElementsByTagName('td');
$i = 0;
foreach ($cells as $cell) {
if ($i++ < 1) {
continue;
}
array_push($a, floatval($cell->nodeValue));
}
print_r($a);
var_dump($a);
echo "<hr/>";
$sql = "INSERT INTO $table (stockcode, lastprice, open, close, low, high)
VALUES ( '" . $data[0] . "', '" . $data[1] . "', '" . $data[4] . "', '" . $data[7] . "', '" . $data[5] . "', '" . $data[6] . "')";
But it still gives me error : PHP Catchable fatal error: Object of class DOMElement could not be converted to string in /var/www/html/mysqlcon.php on line 79
floatval( $data[n]->nodeValue ), but if you edit question adding avar_dumpof$datawe can better help you. - fusion3k$dataconstruction) - fusion3k