【发布时间】:2016-03-21 13:11:35
【问题描述】:
我有codeigniter代码
$this->db->select("items.name as name, items.category as category, items.supplier_id as supplier_id, items.item_number as item_number,
items.product_id as product_id, items.description as description,
items.size as size, items.tax_included as tax_included, items.cost_price as cost_price,
if(price_tiers.name='".$hasilsplit1."',items_tier_prices.unit_price,items.unit_price) as unit_price, items.promo_price as promo_price,
items.start_date as start_date, items.end_date as end_date, items.reorder_level as reorder_level, items.item_id as item_id, items.allow_alt_description as allow_alt_description, items.is_serialized as is_serialized, items.image_id as image_id, items.override_default_tax as override_default_tax, items.is_service as is_service, items.deleted as deleted");
$this->db->from('items');
$this->db->join('items_tier_prices','items_tier_prices.item_id=items.item_id','left');
$this->db->join("price_tiers","price_tiers.id=items_tier_prices.tier_id and price_tiers.name='".$hasilsplit1."'","left");
$this->db->where('items.item_id', $hasilsplit0);
$this->db->where('items.deleted', 0);
它会产生部分错误:
if(price_tiers.name='".$hasilsplit1."',items_tier_prices.unit_price,items.unit_price) as unit_price
错误是:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“as unit_price,items.promo_price as promo_price,items.start_date as sta”附近使用正确的语法
如何在 $this->db->select 中正确编写 IF 语法?
当我 var_dump 时,它显示
选择 items.name 作为名称,items.category 作为类别,items.supplier_id 作为供应商 ID,items.item_number 作为项目编号,items.@88 @ 作为产品 ID,items.description 作为描述,items.size 作为尺寸,items.tax_included 作为含税,items.cost_price 作为成本价格,if(price_tiers.name= 'Jendela Swing Double J106',items_tier_prices.unit_price,items.unit_price) 作为单位价格,items.promo_price 作为促销价格,items.start_date 作为 start_date.@98 987654354@ 作为 end_date,items.reorder_level 作为 reorder_level,items.item_id 作为 item_id,items.allow_alt_description 作为 allow_alt_description,items.@987655436@5 作为 isized 987654364@ 作为 image_id,items.override_default_tax 作为 override_default_tax,items.is_service 作为 is_service,items.deleted 已从 (deleted) 中删除 (deleted) 7332@.ON@@987645344 item_id=items.@98765437 6@ LEFT JOIN price_tiers ON price_tiers.id=items_tier_prices.tier_id and price_tiers.name='Jendela Swing Double J106' WHERE items.item_id = '38@4' AND @98765 .deleted = 0
似乎如果阻止获取字符` 谢谢
【问题讨论】:
-
您遇到了什么错误?你没有指定。
-
嗨@Farside,请检查已编辑的 Question.thx
标签: codeigniter