Heim > Backend-Entwicklung > PHP-Tutorial > thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样

thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样

WBOY
Freigeben: 2016-06-13 12:14:56
Original
1509 Leute haben es durchsucht

thinkphp3.2.3 如何把图片地址合并的字段输出到前台?就是显示图片这样

本帖最后由 u011789405 于 2015-01-22 11:21:03 编辑 实现的是就是文章列表显示文章的图片  TP本身的volist可以输出 但是字段pictureurl 怎么能让前端接收到 直接输出么下面是前端的代码
<br /> <volist name="catecontent" id="content"><br />                <ul class="cate-list"><br /><br />                    <li><h2><a href="">{$content.pictitle}</a></h2></li><br />                    <li class="description">描述:{$content.picdescription}</li><br />                    <li class="picture">{$content.pictureurl }这里是图片地址字段</li><br />                    <li><br />                        <span class="tag">标签:<a href="" target="_blank">{$content.pictag}</a></span><br />                        <span class="author">上传者:{$content.picauthor}</span><br />                    </li><br /><br />                 </ul><br />                </volist><br />
Nach dem Login kopieren

下面是php输出的结果 我想的是图片主题 有多张图片 一张图片一条记录 相同token查询 然后php在进行数组合并 得到这个结果
这个思路对么 这时候想展示图片 怎么搞 直接查询出图片地址 组成数组 ?

这个字段是不是存成二维数组好 直接volist 里面循环volist遍历出图片地址呢

<br />array(2) {<br />  [0] => array(14) {<br />    ["picid"] => string(2) "10"<br />    ["pictitle"] => string(7) "标题2"<br />    ["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(12) "星耀学园"<br />    ["picposttime"] => string(19) "2014-11-26 11:59:50"<br />    ["pictag"] => string(22) "标题2自定义标签"<br />    ["picdescription"] => string(13) "标题2描述"<br />    ["picalbum"] => string(19) "标题2所属相册"<br />    ["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["pictureurl"] => string(223) "attachment/picture/uploadify/20141126/547550273b753.jpg,attachment/picture/uploadify/20141126/547550278b7db.jpg,attachment/picture/uploadify/20141126/54755027ab89b.jpg,attachment/picture/uploadify/20141126/54755027d8488.jpg"<br />    ["creattime"] => string(19) "2014-11-26 11:59:35"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [1] => array(14) {<br />    ["picid"] => string(2) "15"<br />    ["pictitle"] => string(30) "测试更新附件状态字段"<br />    ["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(3) "xxx"<br />    ["picposttime"] => string(19) "2014-12-24 13:40:42"<br />    ["pictag"] => string(30) "测试更新附件状态字段"<br />    ["picdescription"] => string(30) "测试更新附件状态字段"<br />    ["picalbum"] => string(30) "测试更新附件状态字段"<br />    ["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["pictureurl"] => string(223) "attachment/picture/uploadify/20141224/549a51d4a089b.jpg,attachment/picture/uploadify/20141224/549a51d4e6b22.jpg,attachment/picture/uploadify/20141224/549a51d51a0ac.jpg,attachment/picture/uploadify/20141224/549a51d543a33.jpg"<br />    ["creattime"] => string(19) "2014-12-24 13:40:36"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />}<br />
Nach dem Login kopieren


下面是查询出来的原始数据 还没有合并数组 想根据picid 相同的合并 然后字段pictureurl 组成二维数组
这样前台volist 里面在一层volist是不是可以 求熟悉tp的帮忙看看
<br />array(8) {<br />  [0] => array(14) {<br />    ["picid"] => string(2) "10"<br />    ["pictitle"] => string(7) "标题2"<br />    ["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(12) "星耀学园"<br />    ["picposttime"] => string(19) "2014-11-26 11:59:50"<br />    ["pictag"] => string(22) "标题2自定义标签"<br />    ["picdescription"] => string(13) "标题2描述"<br />    ["picalbum"] => string(19) "标题2所属相册"<br />    ["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/547550273b753.jpg"<br />    ["creattime"] => string(19) "2014-11-26 11:59:35"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [1] => array(14) {<br />    ["picid"] => string(2) "10"<br />    ["pictitle"] => string(7) "标题2"<br />    ["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(12) "星耀学园"<br />    ["picposttime"] => string(19) "2014-11-26 11:59:50"<br />    ["pictag"] => string(22) "标题2自定义标签"<br />    ["picdescription"] => string(13) "标题2描述"<br />    ["picalbum"] => string(19) "标题2所属相册"<br />    ["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/547550278b7db.jpg"<br />    ["creattime"] => string(19) "2014-11-26 11:59:35"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [2] => array(14) {<br />    ["picid"] => string(2) "10"<br />    ["pictitle"] => string(7) "标题2"<br />    ["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(12) "星耀学园"<br />    ["picposttime"] => string(19) "2014-11-26 11:59:50"<br />    ["pictag"] => string(22) "标题2自定义标签"<br />    ["picdescription"] => string(13) "标题2描述"<br />    ["picalbum"] => string(19) "标题2所属相册"<br />    ["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/54755027ab89b.jpg"<br />    ["creattime"] => string(19) "2014-11-26 11:59:35"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [3] => array(14) {<br />    ["picid"] => string(2) "10"<br />    ["pictitle"] => string(7) "标题2"<br />    ["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(12) "星耀学园"<br />    ["picposttime"] => string(19) "2014-11-26 11:59:50"<br />    ["pictag"] => string(22) "标题2自定义标签"<br />    ["picdescription"] => string(13) "标题2描述"<br />    ["picalbum"] => string(19) "标题2所属相册"<br />    ["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/54755027d8488.jpg"<br />    ["creattime"] => string(19) "2014-11-26 11:59:35"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [4] => array(14) {<br />    ["picid"] => string(2) "15"<br />    ["pictitle"] => string(30) "测试更新附件状态字段"<br />    ["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(3) "xxx"<br />    ["picposttime"] => string(19) "2014-12-24 13:40:42"<br />    ["pictag"] => string(30) "测试更新附件状态字段"<br />    ["picdescription"] => string(30) "测试更新附件状态字段"<br />    ["picalbum"] => string(30) "测试更新附件状态字段"<br />    ["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141224/549a51d4a089b.jpg"<br />    ["creattime"] => string(19) "2014-12-24 13:40:36"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [5] => array(14) {<br />    ["picid"] => string(2) "15"<br />    ["pictitle"] => string(30) "测试更新附件状态字段"<br />    ["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(3) "xxx"<br />    ["picposttime"] => string(19) "2014-12-24 13:40:42"<br />    ["pictag"] => string(30) "测试更新附件状态字段"<br />    ["picdescription"] => string(30) "测试更新附件状态字段"<br />    ["picalbum"] => string(30) "测试更新附件状态字段"<br />    ["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141224/549a51d4e6b22.jpg"<br />    ["creattime"] => string(19) "2014-12-24 13:40:36"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [6] => array(14) {<br />    ["picid"] => string(2) "15"<br />    ["pictitle"] => string(30) "测试更新附件状态字段"<br />    ["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(3) "xxx"<br />    ["picposttime"] => string(19) "2014-12-24 13:40:42"<br />    ["pictag"] => string(30) "测试更新附件状态字段"<br />    ["picdescription"] => string(30) "测试更新附件状态字段"<br />    ["picalbum"] => string(30) "测试更新附件状态字段"<br />    ["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141224/549a51d51a0ac.jpg"<br />    ["creattime"] => string(19) "2014-12-24 13:40:37"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />  [7] => array(14) {<br />    ["picid"] => string(2) "15"<br />    ["pictitle"] => string(30) "测试更新附件状态字段"<br />    ["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["piccategroy"] => string(1) "9"<br />    ["picauthor"] => string(3) "xxx"<br />    ["picposttime"] => string(19) "2014-12-24 13:40:42"<br />    ["pictag"] => string(30) "测试更新附件状态字段"<br />    ["picdescription"] => string(30) "测试更新附件状态字段"<br />    ["picalbum"] => string(30) "测试更新附件状态字段"<br />    ["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"<br />    ["pictureurl"] => string(55) "attachment/picture/uploadify/20141224/549a51d543a33.jpg"<br />    ["creattime"] => string(19) "2014-12-24 13:40:37"<br />    ["id"] => string(1) "9"<br />    ["categroyname"] => string(6) "动漫"<br />  }<br />}<br /><br />
Nach dem Login kopieren

------解决思路----------------------
问题不在php,而是数据库结构
如果只考虑代码层面,就组二维数组吧~
------解决思路----------------------
文章一张表,图片一张表
一篇文章一条记录,一张图一条记录,图片根据文章id去关联文章
你的冗余数据比较多,也不方便管理

如果在文章列表中需要显示多图,按理说要多表查询,但这样效率太慢
可以在文章表增加一个字段,将图片地址的数组序列化或json_encode后保存
------解决思路----------------------
不理解你想要什么?
你只有一重 volist,那么你示例的数组不正好吗?

不能是从 php 这边向 html 硬凑的
而是先按期望的样式写好 html 代码,php 只是负责向里面填数据
至于数据该是什么样的,要由 html 代码决定
------解决思路----------------------
我提到序列化或json,是为了将php内存中的数组变成字符串存进数据库,用的时候立刻转回来,跟js没关系
------解决思路----------------------
<br />function picurl($str,$id){<br />	//if($width == ''){<br />		$width='200';<br />	//}<br />	<br />	if($str != ''){<br />	$str= explode(",", $str);<br />	$picstr='';<br />	for ($i=0; $i< count($str);  $i++) {<br />		$picstr.='<a href='.U('pls/index',array('id'=>$id)).' target="_blank"><img     style="max-width:90%".$width.'"  src='.$str[$i].' alt="thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样" ></a>  ';<br />	}<br />	<br />	return $picstr;<br />	}<br />}<br />
Nach dem Login kopieren


加个函数进去 模板里头调用函数就可以了 放全局函数里头 这个函数修改下
------解决思路----------------------
本来就是分开的,干嘛要合并在一起?
TP 的模型提供有 Relation 方法,本身就是为了解决你这种问题的
在 volist 里面在逃一个 volist 输出图片就可以了
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage