简体   繁体   English

MySql INNER JOIN导致“怪异”数组

[英]MySql INNER JOIN results in “weird” Array

I'm not that good in advanced MySql and tried to join multiple tables and drop the results into a single PHP-Array. 我在高级MySql中不太好,尝试连接多个表并将结果放入单个PHP数组中。

SELECT * FROM AAA
        INNER JOIN BBB ON AAA.Aufg_id = BBB.Aufg_id
        INNER JOIN CCC ON AAA.SchuelerNr = CCC.schuelernr AND AAA.Schulnummer = CCC.schulnummer AND AAA.Klasse = CCC.klasse
        WHERE AAA.Schulnummer='$x' AND AAA.Klasse='$y' AND AAA.SchuelerNr='$z'

The result is dropped into a 结果放入一个

mysqli_fetch_all($mysqli_result, MYSQLI_BOTH);

therefore I'm able to get the values associative or by number for iterating through a loop. 因此,我可以通过循环来获取关联的值或按数字获取的值。 Almost everything worked fine, except of two values that were not supposed to be there: 除了不应该存在的两个值之外,几乎所有东西都可以正常工作:

[0] => DEMO11
        [sn] => DEMO11
        [1] => 2014-03-31 10:05:14
        [zt] => 2014-03-31 11:47:45
        [2] => 8a_D1
        [kl] => 8a_D1
        [3] => 4
        [snr] => 4
        [4] => 1
        [Aufg_id] => 1
        [5] => f
        [erg] => f
        [6] => 1   <<<< WHERE DOES THIS COME FROM?
        [7] => 1
        [th] => 1
        [8] => Deu
        [fac] => Deu

The value is increasing by one every row. 该值每行增加一。 Its right there between the tables AAA and BBB, without any associative key. 它位于表AAA和BBB之间,没有任何关联密钥。

At the very end of every row, there is a even more irritating value representing a datetime from one of the other columns: 在每一行的末尾,还有一个更令人讨厌的值,它表示来自其他列之一的日期时间:

[43] => 8
[NA_Eng] => 8
[44] => 4
[NA_Fra] => 4
[45] => 2014-03-31 11:47:45 <<<<<< ???

QUESTION: Where do those values come from? 问题:这些值从何而来? How can I get rid of them?? 我如何摆脱它们?

Change your code to: 将您的代码更改为:

mysqli_fetch_all($mysqli_result, MYSQLI_ASSOC);

This way, you'll not get the numeric keys in your results. 这样,您就不会在结果中得到数字键。

See MySQLi predefined constants . 参见MySQLi预定义常量

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

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