簡體   English   中英

僅從 mysqli 查詢返回數據

[英]Returning just data from mysqli query

我正在嘗試從 mysql db 接收數據,但在我的結果中我收到了轉義字符。 我怎樣才能擺脫這些並只返回原始數據(我是這個編碼領域的菜鳥,所以請記住這一點)?

這是我的結果示例(它是一個 json 簽名):

{"簽名":"\\n\\t\\t\\t[{\\"lx\\":16,\\"ly\\":16,\\"mx\\":16,\\"my\\":15},{ \\"lx\\":16,\\"ly\\":17,\\"mx\\":16,\\"my\\":16},{\\"lx\\":16,\\"ly\\":18, \\"mx\\":16,\\"my\\":17},{\\"lx\\":16,\\"ly\\":20,\\"mx\\":16,\\"my\\":18} ,{\\"lx\\":16,\\"ly\\":21,\\"mx\\":16,\\"my\\":20},{\\"lx\\":16,\\"ly\\": 22,\\"mx\\":16,\\"my\\":21},{\\"lx\\":16,\\"ly\\":25,\\"mx\\":16,\\"my\\": 22},{\\"lx\\":16,\\"ly\\":26,\\"mx\\":16,\\"my\\":25},.....]\\n\\t\\t\\ t"}

我想自動刪除: {"signature":"\\n\\t\\t\\t 開頭和 \\n\\t\\t\\t"} 結尾。

任何幫助是極大的贊賞!

<?php
{

    // Connect to MySQL
    $mysqli = new mysqli( 'localhost', 'root', 'rootpassword', 'crs' );

    //Check our connection_aborted
    if ($mysqli->connect_error ) {
        die( 'Connect Error: ' . $mysqli->connect_error );
    }

    //Read the signature
    $sql = "SELECT signature FROM rescue_forms WHERE id=53";
    $idresult = $mysqli->query($sql);


    while($row = mysqli_fetch_assoc($idresults))
        $id = $row;

    //Just printing this so I can see the results.
    print json_encode($id);

    //sending this to a statement below.
    $json = json_encode($id);


    //Close connection
    $mysqli->close();
}

?>

您將 json 存儲在數據庫中,您不應該這樣做,
出於某種原因,您再次對 json 進行編碼,這是毫無意義的。

以一種方式拒絕我的問題並基本上告訴我我是一個白痴,它有幫助! (這是論壇的重點)希望這可以幫助其他可能剛剛開始編寫此類代碼的人。 我能夠像預期的那樣更改我的數組以獲取原始數據,這是我的示例:

<?php
{

    // Connect to MySQL
    $mysqli = new mysqli( 'localhost', 'root', 'rootpassword', 'crs' );

    //Check our connection_aborted
    if ($mysqli->connect_error ) {
        die( 'Connect Error: ' . $mysqli->connect_error );
    }

    //Read the signature
    $sql = "SELECT signature FROM rescue_forms WHERE id=53"; 
    $idresult = $mysqli->query($sql);

    while($sig=mysqli_fetch_assoc($idresult)){

        echo "<tr>";

        echo "<td>".$sig['signature']."</td>";

        echo "</tr>";

    }

    //Close connection
    $mysqli->close();
}

?>

感謝所有回復的人,不勝感激! 還要感謝@YourCommonSense 向我展示了使用您的編輯在此窗口中格式化我的代碼的正確方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM