技术笔记:sku加减号的增删

简介: 技术笔记: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】;


//代码效果参考:http://www.jhylw.com.cn/491325349.html

$arr【'hp_num'】=$data【'hp_num'】【$k】;

$arr【'stock'】=$data【'stock'】【$k】;


$res【】=$arr;


}


print_r($res);


}


//hrml页面 循环输出数据


[/span>center

[/span>tr

[/span>th

商品名称:{$arr【0】【'g_name'】}


货物:{$arr【0】【'hp_num'】}




[/span>table

[/span>form action="{:url('login/add')}"

[/span>input type="hidden" value="{$arr【0】【'goods_id'】}" name="goods_id"/>


[/span>tr

style="color: rgba(0, 0, 255, 1)"]

[/span>td

[/span>td

[/span>td

[/span>td

[/span>td


{volist name="arr" id="vv"}


[/span>tr

[/span>td

[/span>select name="color【】" id="color"

<?php foreach($color as $k =>$v){?>


[/span>option value=""


<?php if($v【'a_val'】==$vv【'attr'】【0】){


echo "selected";


} ?



<?php }?>




[/span>td

[/span>select name="buttor【】" id="buttor"

<?php foreach($buttor as $k =>$v){?>


[/span>option value=""


<?php if($v【'a_val'】==$vv【'attr'】【0】){


echo "selected";


} ?



<?php }?>




[/span>tdinput type="text" value="{$vv【'hp_num'】}" name="hp_num【】"/>

[/span>tdinput type="text" value="{$vv【'stock'】}" name="stock【】"/>

[/span>tdinput type="button" value="+" class="jia"/>


{/volist}


[/span>tr

[/span>tdinput type="submit" value="添加"/>





//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页面 循环输出数据


[/span>center

[/span>tr

[/span>th

商品名称:{$arr【0】【'g_name'】}


货物:{$arr【0】【'hp_num'】}




[/span>table

[/span>form action="{:url('login/add')}"

[/span>input type="hidden" value="{$arr【0】【'goods_id'】}" name="goods_id"/>


[/span>tr

[/span>td

[/span>td

[/span>td

[/span>td

[/span>td


{volist name="arr" id="vv"}


[/span>tr

[/span>td

[/span>select name="color【】" id="color"

<?php foreach($color as $k =>$v){?>


[/span>option value=""


<?php if($v【'a_val'】==$vv【'attr'】【0】){


echo "selected";


} ?



<?php }?>




[/span>td

[/span>select name="buttor【】" id="buttor"

<?php foreach($buttor as $k =>$v){?>


[/span>option value=""

相关文章
|
5月前
|
Java
Java数组的2个小案例(杨辉三角分析和商品管理增删改查)
Java数组的2个小案例(杨辉三角分析和商品管理增删改查)
52 4
|
8月前
【编程题-错题集】分组(枚举 + 二分)
【编程题-错题集】分组(枚举 + 二分)
|
Python
使用Python实现商品价格区间设置和排序
使用Python实现商品价格区间设置和排序
400 0
Axure快速入门(09) -变量和表达式(计算商品总价例子)
Axure快速入门(09) -变量和表达式(计算商品总价例子)
222 0
数据结构上机实践第七周项目3 - 负数把正数赶出队列
数据结构上机实践第七周项目3 - 负数把正数赶出队列
115 0
数据结构上机实践第七周项目3 - 负数把正数赶出队列
|
算法
数据结构上机实践第三周项目3- 求集合并集
数据结构上机实践第三周项目3- 求集合并集
109 0
数据结构上机实践第三周项目3- 求集合并集
开窗函数第一招式(排序聚合我要看顺序)
先看下我找的题目,ENG OMG 放心 我给安排了中文
134 0
开窗函数第一招式(排序聚合我要看顺序)
|
存储 NoSQL 关系型数据库
数据类型-数值增减操作| 学习笔记
快速学习数据类型-数值增减操作
数据类型-数值增减操作| 学习笔记
|
前端开发 开发者
产品-优惠券-类型序选择器|学习笔记
快速学习 产品-优惠券-类型序选择器
产品-优惠券-类型序选择器|学习笔记