我很难弄清楚为什么我从 php 查询中得到空结果:
在我的 mySQL 数据库中,我将 id 定义为:int(11)、Null:No、默认值:None、Extra:AUTO_INCRMENT、 和一些长的花哨(它包括所有可能的文本条目,带有所有符号,如“$%/):...)描述文本,如:varchar(1000),排序规则:utf8_unicode_ci,Null:No,默认值:None。
我可以轻松地在表中插入所有内容,没有任何问题,但是当我通过 php 脚本查询结果时,如下所示:
$result = mysql_query("SELECT *FROM tableX") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// xy node
$response["tableX"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$xy= array();
$xy["id"] = $row["id"];
$xy["desc"] = $row["desc"];
// push single xy into final response array
array_push($response["tableX"], $xy);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
在此查询之后,我得到: id=null 和 desc=null (有时 - 我认为当只有文本时 - 我得到描述的正常预期结果,但 id 始终为 null)。我可以清楚地看到表中的 id,它看起来很正常,但就像我说的,在 php 脚本之后,我得到 null...
有人可以帮我吗?
最佳答案
If you push an array onto the stack, PHP will add the whole array to the next element instead of adding the keys and values to the array. If this is not what you want, you're better off using array_merge() or traverse the array you're pushing on and add each element with $stack[$key] = $value.
<?php
$stack = array('a', 'b', 'c');
array_push($stack, array('d', 'e', 'f'));
print_r($stack);
?>
The above will output this: Array ( [0] => a [1] => b [2] => c [3] => Array ( [0] => a [1] => b [2] => c ) )
关于php - MySQL id null 和一些长而奇特的描述 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150989/