Re: Convert database string
Hi guys, for formatting the array output into a comma-separated string that can be easily used in your JavaScript, you can modify your PHP script by doing the following:
<?php
$hostname = "localhost:3306";
$password = "xxxxxxxx";
$username = "web705";
$usertable = "wp";
$database = "web705";
$db_conn = mysqli_connect($hostname, $username, $password, $database);
$i = 0;
$string1 = [];
$sql = "SELECT * FROM wp ORDER BY DT DESC LIMIT 13";
$db_query = mysqli_query($db_conn, $sql);
if (!$db_query) {
die('Invalid query: ' . mysqli_error($db_conn));
}
while ($row = mysqli_fetch_array($db_query, MYSQLI_ASSOC)) {
$string1[$i] = $row["t1"];
$i++;
}
mysqli_free_result($db_query);
$comma_separated_string = implode(", ", $string1);
echo $comma_separated_string;
?>
Subject
Written By
Posted
Re: Convert database string
August 06, 2024 07:43AM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.