I am still new to PHP. I have tried a few stuff, but I just can't get it to work.
Question: I want all the data from my users
table to be in a string, separated by comma. Then when the ID
is 2
to be ;
for net new row, so on and so forth. If someone can please help me.
$server = "localhost";
$user_name = "root";
$password = "";
$database = "users";
$conn = new mysqli($server, $user_name, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Users;";
$result = $conn ->query($sql);
while($row = mysqli_fetch_array( $result )) {
$rows = implode (";",$result);
$array = $rows;
echo $array;
}
Question2: But if I want first row of DB data to be, separated and then at the end with a ;
. How would I do that?
Output: The output of this code is:
Warning: implode(): Invalid arguments passed