<?php
require_once 'includes/connection.php';
$data = "select * from contacts_tbl";
$query_posi = mysqli_query($con, $data);
while($row = mysqli_fetch_array($query_posi)){
echo $row['contact_number'];
}
?>
the result of that is 09277432079 09236677868
What result I want is {09277432079,10236677868}
My Answer:
To achieve the desired result in the form of {data,data,}, you can modify the code as follows:
php
<?php
require_once 'includes/connection.php';
$data = "select * from contacts_tbl";
$query_posi = mysqli_query($con, $data);
$result = "{";
while($row = mysqli_fetch_array($query_posi)){
$result .= $row['contact_number'] . ",";
}
$result = rtrim($result, ","); // Remove the last comma
$result .= "}";
echo $result;
?>
This code will fetch the data from the database and concatenate the contact numbers in the desired format {data,data,}.
Rate this post
5 of 5 based on 6799 votesComments