PHP 是否在 phpMyAdmin 中重复使用相同名称的变量,还是 print_r 存在缺陷?
Does PHP repeat variables with the same name in phpMyAdmin, or is it a flaw with print_r?
我正在查看 mysql 加入 phpmyadmin 的结果,并将其与 php print_r 转储进行比较,并注意到 print_r 似乎只使用第一个(行)"id" 变量,并跳过第二个。为什么 print_r 不会放像 'tablename."id"' 而不是仅仅消除第二个表 "id" 值的原因?
PHPmyADMIN head dump:
- id inst_id zip id inst_id 技能
PHP 样本转储:
- 数组( [id] => 1 [inst_id] => 1 [zip] => 23456 [skill] => 喵喵 )
print_r
只是按原样打印数组,显然它只有这 4 个具有指定值的索引。
问题出在查询本身。 Table 名称或 table 别名未在字段名称中返回,因此您得到两个名为 id
的字段。由于一个数组不能两次具有相同的键,因此将跳过其中一个。
所以要解决它,通过为字段本身指定别名来更改查询:
SELECT
t1.id as t1_id, -- Key will be t1_id
t2.id as t2_id, -- Key will be t2_id
.. other fields ..
FROM
.. etcetera ...
我正在查看 mysql 加入 phpmyadmin 的结果,并将其与 php print_r 转储进行比较,并注意到 print_r 似乎只使用第一个(行)"id" 变量,并跳过第二个。为什么 print_r 不会放像 'tablename."id"' 而不是仅仅消除第二个表 "id" 值的原因?
PHPmyADMIN head dump:
- id inst_id zip id inst_id 技能
PHP 样本转储:
- 数组( [id] => 1 [inst_id] => 1 [zip] => 23456 [skill] => 喵喵 )
print_r
只是按原样打印数组,显然它只有这 4 个具有指定值的索引。
问题出在查询本身。 Table 名称或 table 别名未在字段名称中返回,因此您得到两个名为 id
的字段。由于一个数组不能两次具有相同的键,因此将跳过其中一个。
所以要解决它,通过为字段本身指定别名来更改查询:
SELECT
t1.id as t1_id, -- Key will be t1_id
t2.id as t2_id, -- Key will be t2_id
.. other fields ..
FROM
.. etcetera ...