Home > Backend Development > PHP Tutorial > 跪求 php将多条数据写入一个字段的方法

跪求 php将多条数据写入一个字段的方法

WBOY
Release: 2016-06-20 12:46:33
Original
1565 people have browsed it

多图片上传处理完成,得到图片地址数组:for ($i = 1; $i <= 20; $i++) {	if($img[$i] != ""){		echo "$img[$i] <br>";	}}这样能输出:file/1.jpgfile/2.giffile/3.pngfile/4.giffile/5.jpg...........由于图片太多,想存入一个字段里,然后每个图片地址前加个 # 号 便于以后读取和修改,效果如:file/1.jpg # file/2.gif # file/3.png # file/4.gif # file/5.jpg跪求下 怎么做才能存入一个img字段?在for里面加上 $data['img'] = '# '.$img[$i].'';但是在外面,insert($data);写进数据库,只有最后一条数据
Copy after login


回复讨论(解决方案)

$data['img'] .= '# '.$img[$i].'';
Copy after login
Copy after login

for每循环一次,就insert一次也可以啊

$data = ""; // 放外面for ($i = 1; $i <= 20; $i++) {    if($img[$i] != ""){        echo "$img[$i] <br>";       $data .= '# '.$img[$i].''    }}
Copy after login
Copy after login

$img = array_diff($img, array(''));$data = join(' # ', $img);
Copy after login

$data = ""; // 放外面for ($i = 1; $i <= 20; $i++) {    if($img[$i] != ""){        echo "$img[$i] <br>";       $data .= '# '.$img[$i].''    }}
Copy after login
Copy after login



你的正确 能用, 但是 你少了个;号 哈哈

$data['img'] .= '# '.$img[$i].'';
Copy after login
Copy after login



感谢 你!
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template