我有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服务器版本相对应的手册,以获得正确的语法,作为unit_price使用,items
。promo_price
作为promo_price,items
。start_date
as STA'在第1行
如何在$ this-> db-> select?
中正确编写IF语法当我在var_dump时,显示
选择items
。name
作为名称,items
。category
作为类别,items
。supplier_id
作为supplier_id,{{1} }。items
作为item_number,item_number
。items
作为product_id,product_id
。items
作为说明,description
。items
as尺寸,size
。items
为tax_included,tax_included
。items
为cost_price,if(price_tiers.name =' Jendela Swing Double J106',{{ 1}}。cost_price
,items_tier_prices
。unit_price
为unit_price,items
。unit_price)
为promo_price,items
。promo_price
为start_date,items
。start_date
为end_date,items
。end_date
为reorder_level,items
。reorder_level
为item_id,items
。 item_id
为allow_alt_description,items
。allow_alt_description
为is_serialized,items
。is_serialized
为image_id,items
。image_id
为override_default_tax, items
。override_default_tax
as is_service,items
。is_service
已删除FROM(items
)LEFT JOIN deleted
ON items
。{ {1}} = items_tier_prices
。items_tier_prices
LEFT JOIN item_id
ON items
。item_id
= price_tiers
。price_tiers
和price_tiers。 name =' Jendela Swing Double J106' WHERE id
。items_tier_prices
=' 1' AND tier_id
。items
= 0
似乎块得到了字符` 感谢
答案 0 :(得分:1)
我认为您需要查看手册,并尝试在compiling SELECT
时禁用转义:
$this->db->select()
接受可选的第二个参数。如果将其设置为FALSE,CodeIgniter将不会尝试保护您的字段或表名称。如果您需要复合选择语句,其中字段的自动转义可能会破坏它们,这非常有用。
第二个建议是在使用原始数据时转义SQL查询,例如:
$this->db->escape($someString); // instead of using $someString when concatenating string for query.