2016-04-07 1 views
0

現在、1はMySQLフィールドに改行が含まれています。新しい行でPHPを使って抽出する方法は? MySQLのDB内のフィールドの

PARTICIPATE 

These are a few areas which would greatly improve with your participation 

すなわち、二つの新しい行があります以下のようなものが含まれています。

しかし、Jsonから抽出すると、新しい行が見つからない、次のようになりました。

{Description: "PARTICIPATE These are a few areas which would greatly improve with your participation"} 

function queryPrintJson($cnx, $query) { 
    $rows=queryReturnJsonArray($cnx, $query); 
    print json_encode($rows); 
} 

function queryReturnJsonArray($cnx, $query) { 
    $result=mysqli_query($cnx, $query) or die ("Can't execute query!"); 
    $rows = array(); 

    while($obj = $result->fetch_object()){ 
     $rows[] = $obj; 
    } 
    $result->close(); 
    return $rows; 
} 

以下のように私のPHPコードは、私は改行を維持することができとにかくありますか? \ nに変換されたら大丈夫です。

答えて

1

PHPの問題の列にすべての改行を<br>に置き換えることができます。最終的には、このようなjavascriptコードを取得するとHTMLになります。

function queryReturnJsonArray($cnx, $query) { 
    $result=mysqli_query($cnx, $query) or die ("Can't execute query!"); 
    $rows = array(); 

    while($obj = $result->fetch_object()){ 
     $obj->col_name = str_replace("\n", '<br>', $obj->col_name); 
     $rows[] = $obj; 
    } 
    $result->close(); 
    return $rows; 
} 
+0

ありがとうございます!それは助けて! – Elye

関連する問題