Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need to fetch data from database but I need the result in this form of {data,data,}

<?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}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I made a loop over your contacts array to demo the concept of visiting those data in a while loop and echoing contacts comma separated and wrapped in parenthesis:

https://onlinephp.io/c/6280d

$contacts = [
    '09277432079',
    '10236677868',
    '10436674963',
    ];

$arrayLength = count($contacts);
$i = 0;
echo '{';
while ($i < $arrayLength)
{
    echo $contacts[$i];
    if($i < $arrayLength-1)
        echo ',';
    $i++;
}
echo '}';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading