【发布时间】:2012-01-12 17:39:12
【问题描述】:
function stationcost($station1,$station2)
{
$data = array();
$this->db->select('Zone')->from('station_zone')->where('Station', $station1);
$Q = $this->db->get();
$this->db->select('cost')->from('zone_cost')->where('zone', $Q);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data = $row->Cost;
return $data;
}
}
}
如果我将 $Q 更改为整数,则该函数可以正常工作。我还没有添加另一个站来减去差异来计算区域差异
将名称转换为区域 $station2 - $station1 = '计算的数字'
然后从 zone_cost 中选择成本 where zone = 'calculated figure';
我的错误信息:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
SELECT `cost` FROM (`zone_cost`) WHERE `zone` =
Filename: models/station_model.php
Line Number: 59
我试过了
$this->db->select('Zone')->from('station_zone')->where('Station', $station2);
$S2 = $this->db->get();
$this->db->select('Zone')->from('station_zone')->where('Station', $station1);
$S1 = $this->db->get();
$Q = $S2 - $S1;
【问题讨论】:
标签: php mysql database forms codeigniter