用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2549|回复: 4
收起左侧

請問這段sql語法要如何改成ci可以用的呢

[复制链接]
发表于 2009-4-22 21:17:15 | 显示全部楼层 |阅读模式
$query = "select psku, pname, pcost, pprice, pskulist from products where pskulist <> ''";
$result = mysql_query($query);
while(
$row = mysql_fetch_row($result)) {
        $query2
= "select sum(pprice) from products where psku in ($row[4])";
}
請問這段sql語法要如何改成ci可以用的呢
发表于 2009-4-22 22:27:49 | 显示全部楼层
试试这样.

$this->db->select('psku, pname, pcost, pprice, pskulist');
$this->db->where('pskulist <>', '');
$query = $this->db->get('products');

$row4 = $query->row(4);
foreach ($query->result() as $row)
{
        query2 = "select sum(pprice) from products where psku in ($row4)";
}
发表于 2009-4-22 22:30:05 | 显示全部楼层
$this->load->database();
$this->db->select('psku', 'pname', 'pcost', 'pprice', 'pskulist');
$this->db->from('products');
$this->db->where('pskulist<>', '""');
$query = $this->db->get();
$result = $query->result(‘array');
$result2 = array();
foreach($result as $res)
{
   $sql = 'select sum(pprice) from products where psku in('.$res['pprice'].')';
   $query = $this->db->query($sql);
   $result2[] = $query->result('array');
}
print_r($result2);

仅供参考:)
发表于 2009-4-23 01:55:22 | 显示全部楼层
直接:
$query = "select psku, pname, pcost, pprice, pskulist from products where pskulist <> ''";
$result  = $this->db->query($query);
......
......
发表于 2009-4-30 16:48:55 | 显示全部楼层
select * from table where (a=1 or b=2) and c=1
这种有好建议么

本版积分规则