sku 加减号的增删
Posted chaihtml
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sku 加减号的增删相关的知识,希望对你有一定的参考价值。
---恢复内容开始---
//php页面
public function test(){
$id="1";
$data=Db::table(‘week3_goods‘)
->join("week3_hp","week3_goods.g_id=week3_hp.goods_id")
->join("week3_goods_attr","week3_hp.g_a_id=week3_goods_attr.g_a_id")
->where("week3_goods.g_id",$id)
->select();
//print_r($data);die;
foreach($data as $k =>$v){
if($v[‘a_id‘]){
$ids=explode(‘,‘,$v[‘a_id‘]);
foreach($ids as $kk =>$vv){
$res=Db::table(‘week3_attr‘)->where("a_id",$vv)->find();
$ids[$kk]=$res[‘a_val‘];
$data[$k][‘attr‘]=$ids;
}
}
}
$color=Db::table(‘week3_attr‘)->where("a_name",‘颜色‘)->select();
$buttor=Db::table(‘week3_attr‘)->where("a_name","内存")->select();
return view("index",[‘color‘=>$color,‘buttor‘=>$buttor,‘arr‘=>$data]);
}
//添加数据
public function add(){
$data=Request::instance()->param();
foreach($data[‘color‘] as $k =>$v){
$arr[‘goods_id‘]=$data[‘goods_id‘];
$arr[‘attr‘]=$data[‘color‘][$k].",".$data[‘buttor‘][$k];
$arr[‘hp_num‘]=$data[‘hp_num‘][$k];
$arr[‘stock‘]=$data[‘stock‘][$k];
$res[]=$arr;
}
print_r($res);
}
//hrml页面 循环输出数据
<center>
<tr>
<th>
商品名称:{$arr[0][‘g_name‘]}
货物:{$arr[0][‘hp_num‘]}
</th>
</tr>
<table>
<form action="{:url(‘login/add‘)}">
<input type="hidden" value="{$arr[0][‘goods_id‘]}" name="goods_id"/>
<tr>
<td>颜色</td>
<td>内存</td>
<td>货号</td>
<td>库存</td>
<td>操作</td>
</tr>
{volist name="arr" id="vv"}
<tr>
<td>
<select name="color[]" id="color">
<?php foreach($color as $k =>$v){?>
<option value="<?php echo $v[‘a_id‘]?>"
<?php if($v[‘a_val‘]==$vv[‘attr‘][0]){
echo "selected";
} ?>><?php echo $v[‘a_val‘];?>
</option>
<?php }?>
</select>
</td>
<td>
<select name="buttor[]" id="buttor">
<?php foreach($buttor as $k =>$v){?>
<option value="<?php echo $v[‘a_id‘]?>"
<?php if($v[‘a_val‘]==$vv[‘attr‘][0]){
echo "selected";
} ?>><?php echo $v[‘a_val‘];?>
</option>
<?php }?>
</select>
</td>
<td><input type="text" value="{$vv[‘hp_num‘]}" name="hp_num[]"/></td>
<td><input type="text" value="{$vv[‘stock‘]}" name="stock[]"/></td>
<td><input type="button" value="+" class="jia"/></td>
</tr>
{/volist}
<tr>
<td><input type="submit" value="添加"/></td>
</tr>
</form>
</table>
</center>
//jquery 界面
//加减号的改变
$(document).on(‘click‘,‘.jia‘,function(){
var obj=$(this).parents("tr").clone();
obj.find(".jia").attr(‘value‘,‘-‘);
obj.find(".jia").attr(‘class‘,‘jian‘);
$(this).parents("tr").after(obj);
});
$(document).on(‘click‘,‘.jian‘,function(){
$(this).parents("tr").remove();
});
---恢复内容结束---
//php页面
public function test(){
$id="1";
$data=Db::table(‘week3_goods‘)
->join("week3_hp","week3_goods.g_id=week3_hp.goods_id")
->join("week3_goods_attr","week3_hp.g_a_id=week3_goods_attr.g_a_id")
->where("week3_goods.g_id",$id)
->select();
//print_r($data);die;
foreach($data as $k =>$v){
if($v[‘a_id‘]){
$ids=explode(‘,‘,$v[‘a_id‘]);
foreach($ids as $kk =>$vv){
$res=Db::table(‘week3_attr‘)->where("a_id",$vv)->find();
$ids[$kk]=$res[‘a_val‘];
$data[$k][‘attr‘]=$ids;
}
}
}
$color=Db::table(‘week3_attr‘)->where("a_name",‘颜色‘)->select();
$buttor=Db::table(‘week3_attr‘)->where("a_name","内存")->select();
return view("index",[‘color‘=>$color,‘buttor‘=>$buttor,‘arr‘=>$data]);
}
//添加数据
public function add(){
$data=Request::instance()->param();
foreach($data[‘color‘] as $k =>$v){
$arr[‘goods_id‘]=$data[‘goods_id‘];
$arr[‘attr‘]=$data[‘color‘][$k].",".$data[‘buttor‘][$k];
$arr[‘hp_num‘]=$data[‘hp_num‘][$k];
$arr[‘stock‘]=$data[‘stock‘][$k];
$res[]=$arr;
}
print_r($res);
}
//hrml页面 循环输出数据
<center>
<tr>
<th>
商品名称:{$arr[0][‘g_name‘]}
货物:{$arr[0][‘hp_num‘]}
</th>
</tr>
<table>
<form action="{:url(‘login/add‘)}">
<input type="hidden" value="{$arr[0][‘goods_id‘]}" name="goods_id"/>
<tr>
<td>颜色</td>
<td>内存</td>
<td>货号</td>
<td>库存</td>
<td>操作</td>
</tr>
{volist name="arr" id="vv"}
<tr>
<td>
<select name="color[]" id="color">
<?php foreach($color as $k =>$v){?>
<option value="<?php echo $v[‘a_id‘]?>"
<?php if($v[‘a_val‘]==$vv[‘attr‘][0]){
echo "selected";
} ?>><?php echo $v[‘a_val‘];?>
</option>
<?php }?>
</select>
</td>
<td>
<select name="buttor[]" id="buttor">
<?php foreach($buttor as $k =>$v){?>
<option value="<?php echo $v[‘a_id‘]?>"
<?php if($v[‘a_val‘]==$vv[‘attr‘][0]){
echo "selected";
} ?>><?php echo $v[‘a_val‘];?>
</option>
<?php }?>
</select>
</td>
<td><input type="text" value="{$vv[‘hp_num‘]}" name="hp_num[]"/></td>
<td><input type="text" value="{$vv[‘stock‘]}" name="stock[]"/></td>
<td><input type="button" value="+" class="jia"/></td>
</tr>
{/volist}
<tr>
<td><input type="submit" value="添加"/></td>
</tr>
</form>
</table>
</center>
//jquery 界面
//加减号的改变
$(document).on(‘click‘,‘.jia‘,function(){
var obj=$(this).parents("tr").clone();
obj.find(".jia").attr(‘value‘,‘-‘);
obj.find(".jia").attr(‘class‘,‘jian‘);
$(this).parents("tr").after(obj);
});
$(document).on(‘click‘,‘.jian‘,function(){
$(this).parents("tr").remove();
});
以上是关于sku 加减号的增删的主要内容,如果未能解决你的问题,请参考以下文章