我有一个存储网站新闻文章的数据库。每行包含时间,标题,作者和内容字段。 Javascript处理从php传递的信息并通过可切换按钮显示它。出于某种原因,即使我在Mysql Workbench中看到数据,一些内容字段也返回null。为什么会这样?
这是我的代码..
var json = <?php
$servername = "sfxworks.net"; //Currently pulls from my webserver. Pass sql credentials or write a php file that I can include that wont show on github.
$username = "foo";
$password = "bar";
$dbname = "foodbarmmmmmmmmm";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$rows = array();
$sql = "SELECT title, author, date, content FROM News";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$rows[] = $row;
}
} else {
echo "0 results";
}
$conn->close();
print json_encode($rows);
?>;
出于某种原因,在php处理错误报告后,我只是随机获取空值。在同一个地方,但随机。
答案 0 :(得分:0)
表格中有一些值有趣的撇号......
从字符串中删除[']并将其替换为[']后,该值不再为空。