douyingmou1389 2015-12-07 17:48
浏览 31

如何知道传入的数组是否与数据库中现有数组的值不同? [关闭]

I am looping through fresh array and my database array. i wanna compare the price and the availability on specific id and date. this is what i got:

            foreach ($this->super_unique($data) as $day_info) {

                $data_listing = Array(
                    'list_id' => $airbnb_id,
                    'list_price' => $day_info['price']['local_price'],
                    'list_currency' => $day_info['price']['local_currency'],
                    'list_date' => $day_info['date'],
                    'list_available' => $this->check_list_available((int)$day_info['available'])
                );
                $listings[] = $data_listing;
            }


            if ($this->Reservations_model->existing_prices(@$listings[0]['list_id']) > 0) {
                foreach ($listings as $list_result) {
                    if ($this->db->where("(list_id = '{$list_result['list_id']}' and list_date = '{$list_result['list_date']}' and list_price NOT = '{$list_result['list_price']}' or list_available NOT = '{$list_result['list_available']}')")) {
                        $this->db->where("(list_id = '{$list_result['list_id']}' and list_date = '{$list_result['list_date']}')");
                        $this->db->update('airbnb_lists_price', $list_result['list_available']);
                        $this->db->update('airbnb_lists_price', $list_result['list_price']);
                    }
                }
                echo 'Prices or avilablity change so we need to update';
            } else {
                $this->db->insert_batch('airbnb_lists_price', $listings);
                echo 'Prices not changed all good';
            }

        }

Getting me

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 'NOT = '70' or list_available NOT = 'FALSE') AND (list_id = '215583' and ' at line 2

UPDATE `airbnb_lists_price` SET `FALSE` = '' WHERE (`list_id` = '215583' and `list_date` = '2015-11-29' and `list_price` `NOT` = '70' or `list_available` `NOT` = 'FALSE') AND (`list_id` = '215583' and `list_date` = '2015-11-29')`

What am i doing wrong?

  • 写回答

1条回答 默认 最新

  • duan0504 2015-12-07 18:02
    关注

    You're performing your comparison incorrectly. Using NOT is improper here:

    `list_price` `NOT` = '70' or `list_available` `NOT` = 'FALSE'
    

    You can use the not-equals operator one of two ways:

    `list_price` != '70' or `list_available` != 'FALSE'
    

    OR

    `list_price` <> '70' or `list_available` <> 'FALSE'
    

    In addition, NOT is a reserved word in MySQL and you should avoid using those words in general. For example, your use of FALSE in this portion of the statement:

    UPDATE `airbnb_lists_price` SET `FALSE` = ''
    

    as a column name could be problematic.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题