欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-02-20 19:10:40
...
thinkphp3.2.3 如何把图片地址合并的字段输出到前台?就是显示图片这样
本帖最后由 u011789405 于 2015-01-22 11:21:03 编辑 实现的是就是文章列表显示文章的图片 TP本身的volist可以输出 但是字段pictureurl 怎么能让前端接收到 直接输出么下面是前端的代码





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

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


array(2) {
[0] => array(14) {
["picid"] => string(2) "10"
["pictitle"] => string(7) "标题2"
["pictoken"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"
["piccategroy"] => string(1) "9"
["picauthor"] => string(12) "星耀学园"
["picposttime"] => string(19) "2014-11-26 11:59:50"
["pictag"] => string(22) "标题2自定义标签"
["picdescription"] => string(13) "标题2描述"
["picalbum"] => string(19) "标题2所属相册"
["pictureid"] => string(32) "fd1215da5d37e70280b5b55d9f87acda"
["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"
["creattime"] => string(19) "2014-11-26 11:59:35"
["id"] => string(1) "9"
["categroyname"] => string(6) "动漫"
}
[1] => array(14) {
["picid"] => string(2) "15"
["pictitle"] => string(30) "测试更新附件状态字段"
["pictoken"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"
["piccategroy"] => string(1) "9"
["picauthor"] => string(3) "xxx"
["picposttime"] => string(19) "2014-12-24 13:40:42"
["pictag"] => string(30) "测试更新附件状态字段"
["picdescription"] => string(30) "测试更新附件状态字段"
["picalbum"] => string(30) "测试更新附件状态字段"
["pictureid"] => string(32) "8083b0b4bbf1c05108006d3d952a01d5"
["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"
["creattime"] => string(19) "2014-12-24 13:40:36"
["id"] => string(1) "9"
["categroyname"] => string(6) "动漫"
}
}


下面是查询出来的原始数据 还没有合并数组 想根据picid 相同的合并 然后字段pictureurl 组成二维数组
这样前台volist 里面在一层volist是不是可以 求熟悉tp的帮忙看看

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


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

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

不能是从 php 这边向 html 硬凑的
而是先按期望的样式写好 html 代码,php 只是负责向里面填数据
至于数据该是什么样的,要由 html 代码决定
------解决思路----------------------
我提到序列化或json,是为了将php内存中的数组变成字符串存进数据库,用的时候立刻转回来,跟js没关系
------解决思路----------------------

function picurl($str,$id){
//if($width == ''){
$width='200';
//}

if($str != ''){
$str= explode(",", $str);
$picstr='';
for ($i=0; $i $picstr.='$id)).' target="_blank">thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样 ';
}

return $picstr;
}
}


加个函数进去 模板里头调用函数就可以了 放全局函数里头 这个函数修改下
------解决思路----------------------
本来就是分开的,干嘛要合并在一起?
TP 的模型提供有 Relation 方法,本身就是为了解决你这种问题的
在 volist 里面在逃一个 volist 输出图片就可以了
thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样
  • 专题推荐