dongshi2588 2016-07-26 03:46
浏览 29

php用于插入具有不同代码编号的相同数据

I have this kind of output table of code asset and asset name

+------------+------------+
| code asset | asset name |
+------------+------------+
|     001    | computer   |
|     001    | computer   |
|     002    | laptop     |
+------------+------------+

for example i want to fill the form same computer but i wanted to show different code asset,what did i get was when i entered the quantity of the computer,it duplicate the code number. it suppose to be like this

+------------+------------+
| code asset | asset name |
+------------+------------+
|     001    | computer   |
|     002    | computer   |
|     003    | laptop     |
+------------+------------+

The form is like this

                 <div class="col-md-6 col-sm-6 col-xs-12">
                      <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Quantity</label>
                        <div class="col-md-9 col-sm-9 col-xs-12">
                          <input type="text" name="quantity" class="form-control">
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Asset Name</label>
                        <div class="col-md-9 col-sm-9 col-xs-12">
                         <input type="text" class="form-control" name="assetname">
                      </div>
                  </div>

i'm using for loop. the action is like this

for($i = 0; $i < $_POST['quantity']; $i++) {
    $inAset = inaset($nosiri,$_POST['assetname']);

    move_uploaded_file($_FILES["file"]["tmp_name"],$target_file);
    if($inAset != 1) echo mysql_error();
}//for loop
  • 写回答

1条回答 默认 最新

  • douzhi4830 2016-07-26 04:37
    关注

    At the time creating the table you need to add primary key on your first column and add auto increment to the column as follows:

    CREATE TABLE table_name (code_asset INT PRIMARY KEY auto_increment, col_name VARCHAR(20),...)
    

    It will automatically add +1 to the next row....

    评论

报告相同问题?

悬赏问题

  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'