Convert database string
Hello
I'm trying to read some data from my database. So far it's worked without any problems. Now I want a read array, which looks like this...
Array ( [0] => 25.88 [1] => 25.88 [2] => 25.88 [3] => 26.00 [4] => 25.81 [5] => 25.88 [6] => 25.75 [7] => 25.94 [8] => 25.69 [9] => 25.69 [10] => 25.62 [11] => 25.62 [12] => 25.75 )
into a readable format for my Javascript.
The format must look like this...
25.88, 25.88, 25.88, 26.00, 25.81, 25.88, 25.75, 25.94, 25.69, 25.69, 25.62, 25.62, 25.75
My script sees this...
-------------------------------------------
<?php
//Database access data
$hostname = "localhost:3306"; // eg,localhost - should not be empty for productive servers
$password = "xxxxxxxx"; // The password of the database
$username = "web705"; // The username of the database
$usertable = "wp"; // Database table name that gets created by setup
$database = "web705"; // Database where Online search records are held
// Connection to DB
$db_conn = mysqli_connect ($hostname, $username, $password, $database);
// Variable for DB array
$i = 0;
// Read the DB
$sql = "SELECT * FROM wp ORDER BY DT DESC LIMIT 13";
//Checks connection and reads data from DB
$db_query = mysqli_query( $db_conn, $sql );
if ( ! $db_query )
{
die('Invalid query: ' . mysqli_error());
}
while ($row = mysqli_fetch_array( $db_query, MYSQLI_ASSOC))
{
echo $row['t1'];
echo ", ";
$string1[$i] = $row["t1"];
$string2[$i] = $row["t2"];
$i++;
}
mysqli_free_result( $db_query );
echo "<br><br>";
print_r($string1);
?>
------------------------------------------------------------
CREATE TABLE `wp` (
`ID` int(11) UNSIGNED NOT NULL,
`DT` timestamp NOT NULL DEFAULT current_timestamp(),
`DATE` date NOT NULL DEFAULT current_timestamp(),
`TIME` time NOT NULL DEFAULT current_timestamp(),
`t1` decimal(6,2) DEFAULT 0.00,
`t2` decimal(6,2) DEFAULT 0.00,
`t3` decimal(6,2) DEFAULT 0.00,
`t4` decimal(6,2) DEFAULT 0.00,
`t5` decimal(6,2) DEFAULT 0.00,
`t6` decimal(6,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Data for table `wp`
--
INSERT INTO `wp` (`ID`, `DT`, `DATE`, `TIME`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`) VALUES
(1, '2024-06-03 10:55:01', '2024-06-03', '12:55:01', 25.00, 24.75, 0.00, 0.00, 0.00, 0.00),
(2, '2024-06-03 11:00:00', '2024-06-03', '13:00:00', 25.12, 24.88, 0.00, 0.00, 0.00, 0.00),
(3, '2024-06-03 11:05:01', '2024-06-03', '13:05:01', 25.06, 24.81, 0.00, 0.00, 0.00, 0.00),
(4, '2024-06-03 11:10:01', '2024-06-03', '13:10:01', 25.19, 25.00, 0.00, 0.00, 0.00, 0.00),
(5, '2024-06-03 11:15:01', '2024-06-03', '13:15:01', 25.31, 25.06, 0.00, 0.00, 0.00, 0.00)
-----------------------------------------------------------------
The PHP version is 8.0.23 !
I have to insert the string like this in Java...
<?php $string1; ?>
Can someone please change the script so that it works?
best regards...