Skip to content
Advertisement

How to print multiple row down JSON result?

I have a JSON result like this:

["D002","D003","L159"]

Here the function:

function getdriverworking() {
    //my db
    $conn = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) or die("FAIL");
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }

    $sql = "SELECT * FROM config_driver WHERE status=3 OR status=2";
    $result1 = mysqli_query($conn,$sql);
    $object_array = array();
    while($row = $result1->fetch_assoc()) {
        
    $object_array[] = $row['id_driver']."n";

    }return $object_array;
}

and I call the function from here:

$total = getdriverworking();
$total1=json_encode($total);
$driver = "Driver Working:n*$total1*";
    $result = [
        'mode' => 'chat', 
        'message' => $driver
    ];

print json_encode($result);

I pass it to WhatsApp chat, output like this:

How to make it to down like this:

D002
D003
L159

Advertisement

Answer

Not sure to understand but try this :

$total = getdriverworking();
$total1 = implode("n", $total);
$driver = "Driver Working:n*$total1*";
    $result = [
        'mode' => 'chat', 
        'message' => $driver
    ];

print json_encode($result);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement