这是我显示json数据的php脚本:
$get_chat = "SELECT * FROM chat WHERE u_id1='$u_id' && u_id2=2 ORDER BY data DESC";
$run_chat = $conn->query($get_chat);
if ($run_chat->num_rows > 0) {
while($chat_row = $run_chat->fetch_assoc()) {
echo json_encode( $chat_row );
}
}
这是我的php文件结果:
{"u_id1":"1","content":"ae","u_id2":"2","data":"17\/03\/27 02:02"}
{"u_id1":"1","content":"ax","u_id2":"2","data":"17\/03\/27 02:01"}
{"u_id1":"1","content":"fd","u_id2":"2","data":"17\/03\/26 11:49"}
{"u_id1":"1","content":"hh","u_id2":"2","data":"17\/03\/26 11:47"}
现在我想用html显示所有这些内容。
答案 0 :(得分:0)
尝试类似:
<?php while($chat_row = $run_chat->fetch_assoc()): ?>
<p><?= $chat_row['content']; ?></p>
<?php endwhile; ?>
除非你想要我理解的Javascript对象,否则不需要使用json_encode,而且这似乎不是你想要做的。