thinkphp3.2.3 怎么把图片地址合并的字段输出到前台?就是显示图片这样
程序员文章站
2022-06-15 16:50:37
...
thinkphp3.2.3 如何把图片地址合并的字段输出到前台?就是显示图片这样
本帖最后由 u011789405 于 2015-01-22 11:21:03 编辑 实现的是就是文章列表显示文章的图片 TP本身的volist可以输出 但是字段pictureurl 怎么能让前端接收到 直接输出么下面是前端的代码
下面是php输出的结果 我想的是图片主题 有多张图片 一张图片一条记录 相同token查询 然后php在进行数组合并 得到这个结果
这个思路对么 这时候想展示图片 怎么搞 直接查询出图片地址 组成数组 ?
这个字段是不是存成二维数组好 直接volist 里面循环volist遍历出图片地址呢
下面是查询出来的原始数据 还没有合并数组 想根据picid 相同的合并 然后字段pictureurl 组成二维数组
这样前台volist 里面在一层volist是不是可以 求熟悉tp的帮忙看看
------解决思路----------------------
问题不在php,而是数据库结构
如果只考虑代码层面,就组二维数组吧~
------解决思路----------------------
文章一张表,图片一张表
一篇文章一条记录,一张图一条记录,图片根据文章id去关联文章
你的冗余数据比较多,也不方便管理
如果在文章列表中需要显示多图,按理说要多表查询,但这样效率太慢
可以在文章表增加一个字段,将图片地址的数组序列化或json_encode后保存
------解决思路----------------------
不理解你想要什么?
你只有一重 volist,那么你示例的数组不正好吗?
不能是从 php 这边向 html 硬凑的
而是先按期望的样式写好 html 代码,php 只是负责向里面填数据
至于数据该是什么样的,要由 html 代码决定
------解决思路----------------------
我提到序列化或json,是为了将php内存中的数组变成字符串存进数据库,用的时候立刻转回来,跟js没关系
------解决思路----------------------
加个函数进去 模板里头调用函数就可以了 放全局函数里头 这个函数修改下
------解决思路----------------------
本来就是分开的,干嘛要合并在一起?
TP 的模型提供有 Relation 方法,本身就是为了解决你这种问题的
在 volist 里面在逃一个 volist 输出图片就可以了
{$content.pictitle}
- 描述:{$content.picdescription}
- {$content.pictureurl }这里是图片地址字段
标签:{$content.pictag}
上传者:{$content.picauthor}
下面是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"> ';
}
return $picstr;
}
}
加个函数进去 模板里头调用函数就可以了 放全局函数里头 这个函数修改下
------解决思路----------------------
本来就是分开的,干嘛要合并在一起?
TP 的模型提供有 Relation 方法,本身就是为了解决你这种问题的
在 volist 里面在逃一个 volist 输出图片就可以了
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论