---恢复内容开始---
//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=""