我移动到codeigniter,然后我的sql查询工作,但现在我在框架上它没有。我试图回合时间,这是我的疑问:
SELECT
DATE_FORMAT(wo.dateCreated,'%m/%d/%Y @ %h:%i %p') AS dateCreated
, wo.id
, sr.id AS srid
, ROUND((TIME_TO_SEC(sr.endtime) -
TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) AS totalHours
, ROUND((TIME_TO_SEC(sr.endtime) -
TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) - sr.deduction AS deductHours
, l.name AS locationName
, l.address
, l.zip
FROM company AS c
我缩短了查询,所以它不会那么长,基本上我只需要知道如何使用codeigniter正确地执行ROUND部分。任何帮助将不胜感激!
修改 我改变了你的建议,这给了我这个:
public function get_sr($id) {
$this->db->select('
sr.id
,sr.woid
,sr.description
,sr.techId
,sr.startTime
,sr.endTime
,ROUND((TIME_TO_SEC(sr.endtime) - TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) AS totalHours
,u.first_name
,u.last_name
,rt.value AS rate
,wo.tid');
$this->db->from('service_report sr');
$this->db->join('work_orders wo','wo.id = sr.woid','left');
$this->db->join('enum_rate_type rt','rt.id = sr.rateType','left');
$this->db->join('users u','u.id = sr.techId','left');
$this->db->where('sr.woid', $id);
$query = $this->db->get();
return $query->result_array();
但现在我在调用时遇到错误: 致命错误:在非对象上调用成员函数result_array()
没有ROUND行,显示正常。
这是我的观点:
<?php
$total = 0;
foreach ($srInfo as $row):
$total += $amount = $row['rate'] * $row['deductHours'];
?>
<tbody>
<!-- Cart item -->
<tr>
<td class="center"><?php echo $row['id']; ?></td>
<td>
<h5><?php echo $row['description']; ?></h5>
</td>
<td class="center"><?php echo $row['first_name']; ?> <?php echo $row['last_name']; ?></td>
<td class="center"><?php echo $row['deductHours']; ?></td>
<td class="center"><?php echo "$" . number_format($total, 2); ?></td>
</tr><!-- // Cart item END -->
<?php endforeach; ?>
</tbody>