我在http://97.74.37.64/有一个表格(先访问它)。它只有一个文本区域,访问者可以填写多达15000个手机号码。提交后,它应该转换成一个数组(这是我做过的)。
现在,这个数组如下所示..
Array ( [0] => 9810000000 [1] => 9810000001 [2] => 9810000002 [3] => 9810000003 [4] => 9810000004 [5] => 9810000005 [6] => 9810000006 [7] => 9810000007
等等.. 现在,我想将数组的键更改为字符串" number"所以它应该像
Array ( [number] => 9810000000 [number] => 9810000001 [number] => 9810000002 [number] => 9810000003 [number] => 9810000004 [number] => 9810000005 [number] => 9810000006 [number] => 9810000007
我想做上面提到的事情。因为我想将手机号码插入MySQL表格(每行一个手机号码)。这是MySQL表中的多次插入。我的表名为srchlist
,其中包含2个字段id
(其auto_increment&我们不需要提及或插入)和number
我将数组键作为数字。所以最后它应该像下面那样插入
id | number
---------------
1 9810000000
2 9810000001
3 9810000002
等应插入整个数组值。
答案 0 :(得分:0)
将这些值组织成数组数组怎么样?这样,您可以将它们批量插入到表中,或者在需要时将它们作为循环的一部分插入:
//optional - download videos to local storage (requires "android.permission.WRITE_EXTERNAL_STORAGE" in manifest or ask in runtime)
recyclerView.setDownloadPath(Environment.getExternalStorageDirectory() + "/MyVideo"); // (Environment.getExternalStorageDirectory() + "/Video") by default
recyclerView.setDownloadVideos(true); // false by default
//extra - start downloading all videos in background before loading RecyclerView
List<String> urls = new ArrayList<>();
for (MyModel object : modelList) {
if (object.getVideo_url() != null && object.getVideo_url().endsWith(".mp4"))
urls.add(object.getVideo_url());
}
recyclerView.preDownload(urls);
recyclerView.setAdapter(mAdapter);
//to init videos before scrolling
recyclerView.smoothScrollBy(0, 1);
recyclerView.smoothScrollBy(0, -1);
答案 1 :(得分:0)
您可以这样做:
控制器:
// Array ( [0] => 9810000000 [1] => 9810000001 [2] => 9810000002 [3] => 9810000003 [4] => 9810000004 [5] => 9810000005 [6] => 9810000006 [7] => 9810000007)
$number = array('9810000000','9810000001','9810000002','9810000003',,'9810000004','9810000005','9810000006','9810000007');
foreach($number as $row)
{
$number1[]['number'] = $row;
}
$this->M_admin->numbers($number1); //call modal function
模态:
function numbers($number)
{
// insert into db as batch
$this->db->insert_batch('numbers', $number);
}