Add/delete SKU addition/Subtraction

Source: Internet
Author: User
Tags php foreach

 

--- 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.