douluogu8713 2019-02-15 18:51
浏览 67

创建多维数组

How about, I entered a series of numbers in a doing the separation by means of a comma (,) When we press the SEND button, each of those numbers is entered into the BD, with a different ID. Example: We enter values = 5,6,7,8,9

In the BD they are saved in this way:

Id  values
1      5
2      6 
3      7
4      8
5      9

What I want is to add an Example: Enter the values = 5,6,7,8,9

We enter the cost = 100

I want that when entering the series [5,6,7,8,9] What cost to them is the cost = 100

That is, in the BD be saved in this way:

Id   values cost
1   5      100
2   6      100
3   7      100
4   8      100
5   9      100

Code:

Index.php

<html>

<head>
<title></title>
<meta name="robots" content="noindex, nofollow" />
</head>

<body>

<form method="POST" action="process_values.php">

    <p><textarea rows="20" name="values" cols="40"></textarea></p>

    <input type="text" name="cost" value="" placeholder="cost">

    <p><input type="submit" value="Submit" name="B1"></p>
</form>

</body>

</html>

process_values.php

<?php
error_reporting(-1);
ini_set("display_errors", 1);


$value = $_POST["values"];        //We receive textarea values

$valore = chop($value);    // Eliminate line breaks and space, but only at the end of the chain

$val = nl2br($valore);         // We add the line breaks <br />

$array_datos = explode(",", $val);   // Create an array with the received data using as a separator (,)


    foreach ($array_datos as $value)         // We create a foreach loop
    {

      include("$_SERVER[DOCUMENT_ROOT]/CN/connexion.php");

    $_SAVE_SQL = "INSERT INTO nombre_tabla (values) VALUES ('".$value."')";
    $mysqli->query($_SAVE_SQL);

    }

?>
<html>


<body>

</table>

<table border="1" width="600" id="table1">
    <tr>
        <td>ID</td>
        <td>VALUES</td>
    </tr>
<?PHP
/*******************************************************************************
* CONSULTING DATA TO THE BD
*******************************************************************************/
if ($res = $mysqli->query("SELECT * FROM table_name ORDER BY id ASC", MYSQLI_USE_RESULT)) {
  /*******************************************************************************
  * The while loop that runs through each record and shows each field in the table.
  *******************************************************************************/
  while ($row = mysqli_fetch_array($res)){
    echo "
        <tr>
            <td>".$row['id']."</td>
            <td>".$row['values']."</td>
        </tr>

    ";
  }
}
?>

</body>

</html>
  • 写回答

2条回答 默认 最新

  • dongxun1244 2019-02-15 18:58
    关注

    It's confusing as on the above table you have mentioned values as 5,6,7,8,9 and in below table you have made it cost.

    As per question I think you need something like

    Id  values cost
    1   5      100
    2   6      100
    3   7      100
    4   8      100
    5   9      100
    

    Add it below where you are getting Values

    $cost = $_POST["cost"];

    Just modify your SQL query(considering you have column cost added in database): $_SAVE_SQL = "INSERT INTO nombre_tabla (values,cost) VALUES ('".$value."',$cost)";

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏