0

我搬到了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>
4

0 回答 0