简体   繁体   English

为什么我的代码写入限制为1?

[英]Why does my code have a Limit of 1 with writing it?

I have a code who should read all the rows from a mysql database table. 我有一个代码谁应该读取mysql数据库表中的所有行。 However, it doesn't show all the data from the table. 但是,它不会显示表中的所有数据。

The $array should contains all the rows , but contains only the first. $ array应包含所有行,但仅包含第一行。

I have three row in my module_cmds database 我的module_cmds数据库中有三行

+--------+------+----+--------------------+
| module | hash | id | serverId           |
+--------+------+----+--------------------+
| music  |    1 |  1 | 231870365863903232 |
| rule34 |    1 |  2 | 231870365863903232 |
| logs   |    1 |  3 | 231870365863903232 |
+--------+------+----+--------------------+

FYI, count($reponses) = 1 仅供参考,计数($ reponses)= 1

Try to change the ORDER BY 尝试更改ORDER BY

FYI, The $array, is use previously in the code, but I don't think it change something FYI,$数组,以前在代码中使用,但我认为它不会改变某些东西

$array = array();
    $reponses = $bdd->query('SELECT * FROM module_cmds WHERE serverId=' . $donnees['server_id'] . ' ORDER BY module');
    while ($donnee = $reponses->fetch()){
                $array_param = array();
                $reponses = $bdd->query('SELECT * FROM module_params WHERE idModule=' . $donnee['id']);
                while ($donne = $reponses->fetch()){
                        $array_param_in = array( 'param' => $donne['paramName'],
                                                        'value' => $donne['value']);
                        array_push($array_param,$array_param_in);
                }
        $array_in = array( 'module' => $donnee['module'],
                        'hash' => $donnee['hash'],
                        'params' => $array_param);
        array_push($array,$array_in);
    }

For an ORDER BY module the answer is 对于ORDER BY模块,答案是

"modules":[{"module":"logs","hash":"1","params":[]}]

For an ORDER BY id the answer is 对于ORDER BY id,答案是

"modules":[{"module":"music","hash":"1","params":[]}]

The answer should be 答案应该是

"modules":[{"module":"logs","hash":"1","params":[]},
           {"module":"music","hash":"1","params":[]},
           {"module":"rule34","hash":"1","params":[]},]```

I think the mistake come from the SQL, but 我认为错误来自SQL,但是

'SELECT * FROM module_cmds WHERE serverId = 231870365863903232 ORDER BY module'

work fine. 工作得很好。

Where is my mistake ? 我的错误在哪里? Is it something that I don't know about array in Php ? 是不是我不知道Php中的数组? Some typo ? 有些拼写错误? Some line I forget ? 有些线我忘记了?

FYI, I have a similar code where I don't go into in another SQL Table, and it work perfectly there. 仅供参考,我有一个类似的代码,我没有进入另一个SQL表,它在那里工作得很好。

尝试在第二个while循环中更改$reponses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM