Preserve line breaks in mysqli fetch_assoc( ) PHP

前端 未结 2 1799
-上瘾入骨i
-上瘾入骨i 2021-01-18 23:15

I am trying to get all the rows from my MySQL database using the following code:

$sql = \"SELECT * FROM myTable\";
$result = $conn->query($sql);
    while         


        
2条回答
  •  轮回少年
    2021-01-18 23:48

    Using array_map you can call the function, so with the value of each $row you can get the values.

    $sql = "SELECT * FROM myTable";
     $result = $conn->query($sql);
         while($row = $result->fetch_assoc()) {
             $output[]=array_map("nl2br",$row);
         }
    echo json_encode($output);
    

提交回复
热议问题