【问题标题】:Getting Array From Mysql database and get data from user in form of array ,how insert data array into fetched Array Php从 Mysql 数据库获取数组并以数组形式从用户获取数据,如何将数据数组插入到获取的数组 Php
【发布时间】:2020-08-09 09:43:45
【问题描述】:

我从表单中获取用户数据并将该数据存储在 $data 数组中,第一次将数组插入到 主数组 Like [{sub array1} ] 第二次 再次从用户那里获取新数据并从数据库中获取数据并 将新数据数组插入到获取的数组中 数据应该像这样上传 [{sub array1} ,{sub array2}]

【问题讨论】:

  • 尽量清楚,发布你想要的。
  • @PascalTovohery 你可以为此编写 php 代码吗...你需要了解什么?

标签: php mysql arrays


【解决方案1】:

我不知道这是否是您所要求的,但是从数据库存储/获取数组的一种简单方法就是将您的数组存储为由 ","这样的字符分隔的字符串> 或 ";" (当然要确保不要在字符串中使用它) 喜欢:

// code to upload array as string
$array = array("1","2","3");
$arraytostring = '';
$arraycounter = 1; // counter for check the last element
foreach($array as $element){
   $arraytostring .= $element;
   if($arraycounter != count($array)){ // don't print the char if this is the last
      $arraytostring .= ",";
   }
}
// now $arraytostring is your array as a text then you can upload with your db script
// the code to easily retrieve the array

$array = explode(',',$row['column']);

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 2016-04-10
    • 2016-07-16
    • 2017-09-28
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多