--- Restore content start ---
// PHP page
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", 'color')-> select ();
$ Buttor = DB: Table ('week3 _ ATTR ')-> where ("a_name", "Memory")-> select ();
Return view ("Index", ['color' => $ color, 'buttor' => $ buttor, 'arr' => $ data]);
}
// Add 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 page cyclic output data
<Center>
<Tr>
<TH>
Product Name: {$ arr [0] ['G _ name']}
Goods: {$ 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> color </TD>
<TD> memory </TD>
<TD> renew </TD>
<TD> Inventory </TD>
<TD> operation </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 = "add"/> </TD>
</Tr>
</Form>
</Table>
</Center>
// Jquery Interface
// Change the addition/subtraction number
$(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();
});
--- Restore content end ---
// PHP page
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", 'color')-> select ();
$ Buttor = DB: Table ('week3 _ ATTR ')-> where ("a_name", "Memory")-> select ();
Return view ("Index", ['color' => $ color, 'buttor' => $ buttor, 'arr' => $ data]);
}
// Add 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 page cyclic output data
<Center>
<Tr>
<TH>
Product Name: {$ arr [0] ['G _ name']}
Goods: {$ 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> color </TD>
<TD> memory </TD>
<TD> renew </TD>
<TD> Inventory </TD>
<TD> operation </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 = "add"/> </TD>
</Tr>
</Form>
</Table>
</Center>
// Jquery Interface
// Change the addition/subtraction number
$(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();
});
Add/delete SKU addition/Subtraction