doufang7385 2012-01-13 16:36
浏览 63

Codeigniter编译查询

Hi Codeigniter Experts.

I'm compiling a QUERY by several calls to a function.

When it is done I'll use the QUERY to retrieve some data of course.

Each call, calls another function which gets and returns some translations which is supposed to be used in the QUERY

But it seems like that the WHERE condition in translation funciton gets concatinated by the WHERE condition which I'm compiling in the main QUERY

private function add_to_asq($field_name, $values)
{
.
.
.
.
    $result = array();
    foreach( $values[$last_level] as $val )
    {
           foreach( $val as $v  )
           {
          $result[] = $this->db->escape( $this->asq_value_translate( $last_level, $v, $field_name ) );
        }
    }

    $this->db->where_in( sprintf( '%1$s' , $field_name  ) , implode( ',' , $result ) );

}


    private function asq_value_translate( $level, $value_md5 , $field_name )
    {   
        $this->db->select( sprintf( 'level_%1$d, level_%1$d_value' , $level ) )
        ->distinct()
        ->from('search_options_tree_view')
        ->where( sprintf( 'md5( level_%1$d_value ) = ' , $level ), $value_md5 )
        ->where( 'field_name' , $field_name );
        $q = $this->db->get();
        $value_name = sprintf( 'level_%1$d' , $level );
        $row = $q->row(0);
        $q->free_result();
        return $row->$value_name;       
    }

and the DB complains about it

Error Number: 1054

Unknown column 'type' in 'where clause'

SELECT DISTINCT `level_1`, `level_1_value` FROM (`search_options_tree_view`) WHERE 

`type` IN ('\'Forhandler\'')

 AND md5( level_1_value ) = '138be735c55896dbdbea9b6c5d503b6f' AND `field_name` = 'fuel'

Filename: C:\wamp\www\system\database\DB_driver.php

Line Number: 330

As you see the type IN ('\'Forhandler\'') has not anything to with the asq_value_translation.

Do you have a suggestion?

I've thought of cloning the db-object but then I thought that I ask first and shoot later.

Thanks a lot and have a nice time.

  • 写回答

1条回答 默认 最新

  • dptgpyl61857413 2012-01-13 17:05
    关注

    You should use $this->db->last_query() to see what the output of your query actually is. Then take that query and run it in your db client to make sure the issue is not in codeigniter, but rather in your query.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么