这段代码是什么意思?

2016-07-07 15:04 来源:www.chinab4c.com 作者:ecshop专家

谁能帮我解释一下以下这段代码,代码摘自admin/goods.php文件,作用是添加商品时处理关联商品的,但是写法我看不懂了。请哪位大大帮我解释一下,谢谢了。


// 关联商品
$sql = "DELETE FROM " . $ecs->table('link_goods') .
" WHERE (goods_id = 0 OR link_goods_id = 0)" .
" AND admin_id = '$_SESSION[admin_id]'";
$db->query($sql);
$sql = "SELECT '0' AS goods_id, link_goods_id, is_double, '$_SESSION[admin_id]' AS admin_id" .
" FROM " . $ecs->table('link_goods') .
" WHERE goods_id = '$_REQUEST[goods_id]' ";
$res = $db->query($sql);
while ($row = $db->fetchRow($res))
{
$db->autoExecute($ecs->table('link_goods'), $row, 'INSERT');
}
$sql = "SELECT goods_id, '0' AS link_goods_id, is_double, '$_SESSION[admin_id]' AS admin_id" .
" FROM " . $ecs->table('link_goods') .
" WHERE link_goods_id = '$_REQUEST[goods_id]' ";
$res = $db->query($sql);
while ($row = $db->fetchRow($res))
{
$db->autoExecute($ecs->table('link_goods'), $row, 'INSERT');
}

回答:
这个怎么解释,要看具体哪句话看不懂了

第一句,还有SELECT '0' 是干嘛

先把关联商品进入数据库.默认ID为0.如果当goods_id产生的时候,就update关联商品表的ID.那不就和商品ID对应上了。就这个意思