doushengyou2617 2010-02-19 00:14
浏览 43
已采纳

任何人都可以帮我把它作为一个对象。 (PHP)

Hey, can someone help me make this an object please.

Obviously not all my code is here, but i'm sure you'll get the gist.

<?php
$product_name_1 = $_POST['product_name_1'];
$region_1 = $_POST['region_1'];
$start_date_1 = $_POST['start_date_1'];
$end_date_1 = $_POST['end_date_1'];
$sku_1 = $_POST['sku_1'];

$product_name_2 = $_POST['product_name_2'];
$region_2 = $_POST['region_2'];
$start_date_2 = $_POST['start_date_2'];
$end_date_2 = $_POST['end_date_2'];
$sku_2 = $_POST['sku_2'];

$product_name_3 = $_POST['product_name_3'];
$region_3 = $_POST['region_3'];
$start_date_3 = $_POST['start_date_3'];
$end_date_3 = $_POST['end_date_3'];
$sku_3 = $_POST['sku_3'];
?>



<form action="" method="post" accept-charset="utf-8">
<div id="product_information">
<table id="product_1">
    <tr>
        <th><label for="product_name">Product Name</label></th>
        <th><label for="region">Select A Region</label></th>
        <th class="date"><label for="start_date">Start Date</label></th>
        <th class="date"><label for="end_date">End Date</label></th>
        <th><label for="sku">SKU</label></th>
    </tr>
    <tr>
        <td><input type="text" name="product_name_1" value="" id="product_name_1"></td>
        <td><input type="radio" name="region_1" value="upper_north" id="upper_north_1"><label for="upper_north_">Upper North Island</label><br />
                <input type="radio" name="region_1" value="lower_north" id="lower_north_1"><label for="lower_north_">Lower North Island</label><br />
                <input type="radio" name="region_1" value="south_island" id="south_island_1"><label for="south_island">South Island</label>   </td>
        <td class="date"><input type="text" class="date" name="start_date_1" value="" id="start_date_1"></td>
        <td class="date"><input type="text" class="date" name="end_date_1" value="" id="end_date_1"></td>
        <td><input type="text" name="sku_1" value="" id="sku_1"></td>
    </tr>
</table>
<span class="product"></span>
<div class="add-product">&nbsp;</div>
</div>

<script type="text/javascript" charset="utf-8">

var i = 1;

$('.add-product').click(function(){
    i++;
    $('span.product').replaceWith('<table id="product_'+i+'">'
        +'<tr>'
            +'<th><label for="product_name">Product Name</label></th>'
            +'<th><label for="region">Select A Region</label></th>'
            +'<th class="date"><label for="start_date">Start Date</label></th>'
            +'<th class="date"><label for="end_date">End Date</label></th>'
            +'<th><label for="sku">SKU</label></th>'
        +'</tr>'
        +'<tr>'
            +'<td><input type="text" name="product_name'+i+'" value="" id="product_name'+i+'"></td>'
            +'<td><input type="radio" name="region'+i+'" value="upper_north" id="upper_north'+i+'"><label for="upper_north'+i+'">Upper North Island</label><br />'
                    +'<input type="radio" name="region'+i+'" value="lower_north" id="lower_north'+i+'"><label for="lower_north'+i+'">Lower North Island</label><br />'
                    +'<input type="radio" name="region'+i+'" value="south_island" id="south_island"><label for="south_island">South Island</label>   </td>'
            +'<td class="date"><input type="text" class="date" name="start_date'+i+'" value="" id="start_date'+i+'"></td>'
            +'<td class="date"><input type="text" class="date" name="end_date'+i+'" value="" id="end_date'+i+'"></td>'
            +'<td><input type="text" name="sku'+i+'" value="" id="sku'+i+'"></td>'
        +'</tr>'
    +'</table>'
    +''
    +'<span class="product"></span>');
});
</script>
  • 写回答

4条回答 默认 最新

  • dongpiao9078 2010-02-19 01:21
    关注

    So now onto instantiating and using the new object.

    Could i make a construct like this?

    <? 
    class Product {
    
      private $Name;
      private $Region;
      private $StartDate;
      private $EndDate;
      private $Sku;
      public $i;
    
        function __construct($Name="product_name_$i" $Region="region_$i" $StartDate="start_date_$i" $EndDate="end_date_$i" $Sku="sku_$i")
        {
            $i++
        }
    
    }
    ?>
    

    And then how would i actually instantiate the object and use it in my code?.. can i do this with my JavaScript?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用