简体   繁体   中英

Getting Array From Mysql database and get data from user in form of array ,how insert data array into fetched Array Php

i'm geting data from user from form and storing that data in $data array, 1st time it insert array in to main array Like [{sub array1} ] 2nd time get new data from user again and fetch data from database and insert new data array into fetched array Data should be upload like [{sub array1},{sub array2}]

I don't know if this is what u are asking for but an easy way of storing/getting array from a database is just storing your array as a string separated by a character like "," or ";"(of course make sure you don't use it in your string) like:

// 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']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM