Maison > développement back-end > tutoriel php > 跪求 php将多条数据写入一个字段的方法

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-06-20 12:46:33
original
1636 Les gens l'ont consulté

多图片上传处理完成,得到图片地址数组: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);写进数据库,只有最后一条数据
Copier après la connexion


回复讨论(解决方案)

$data['img'] .= '# '.$img[$i].'';
Copier après la connexion
Copier après la connexion

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

$data = ""; // 放外面for ($i = 1; $i <= 20; $i++) {    if($img[$i] != ""){        echo "$img[$i] <br>";       $data .= '# '.$img[$i].''    }}
Copier après la connexion
Copier après la connexion

$img = array_diff($img, array(''));$data = join(' # ', $img);
Copier après la connexion

$data = ""; // 放外面for ($i = 1; $i <= 20; $i++) {    if($img[$i] != ""){        echo "$img[$i] <br>";       $data .= '# '.$img[$i].''    }}
Copier après la connexion
Copier après la connexion



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

$data['img'] .= '# '.$img[$i].'';
Copier après la connexion
Copier après la connexion



感谢 你!
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal