我正在尝试将 php mysql 语句转换为 Codeigniter 语法。该代码从数据库中选择所有内容,但区域差异等于两个表单输入相减。非常感谢任何帮助。
PHP版本
select * from zone_cost where zone_diff =
@(
(select zone from station_zone where station ='FORMINPUT') - (select zone from station_zone where station ='FORMINPUT')
);
Codeigniter尝试版本
$zd = (
$this->db->select('zone');
$this->db->get_where('station_zone','station' => $this->form->input('station'));
) - ($this->db->select('zone');
$this->db->get_where('station_zone','station' => $this->form->input('station2'));
);
$this->db->select('zone_cost');
$this->db->where('zone_diff', $zd);
最佳答案
我认为你应该用mysql做减法:
SELECT
station_zone.zone-sz2.zone as ZoneDiff
FROM station_zone
JOIN station_zone AS sz2 ON (sz2.station="station2")
WHERE station_zone.station="station1"
它尚未经过测试,但我认为您可以使用类似的查询。之后,您可以合并主要查询,这样您只需要一个查询即可“回答”完整的数据问题。
关于PHP 到 Codeigniter 语法 - 从 db/form 输入中选择减法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8835299/