php - MySQL id null 和一些长而奇特的描述 null

标签 php mysql sql

我很难弄清楚为什么我从 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 ) )

发现于http://php.net/manual/en/function.array-push.php .

关于php - MySQL id null 和一些长而奇特的描述 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150989/

相关文章:

php - 从数组中找出特定的键?

Mysql:获取日期的最小值和最大值

mysql - SQL 查询 : Getting the top five tuples based on a value where the value could be the same for some tuples

mysql - 如何在两个字段上使用 COUNT 和 GROUP BY

php - PHP创建表脚本并在表中插入数据

PHP $_POST 数组为空,但是 $_GET 完好无损

php - Zend Validate - 多个值

显示表中最后一行值的 PHP 数组

PHP 表单/Mysql INSERT INTO 不起作用

java - JPA 标准 API : LEFT JOIN for optional relationships