实现的是就是文章列表显示文章的图片 TP本身的volist可以输出 但是字段pictureurl 怎么能让前端接收到 直接输出么下面是前端的代码
<volist name="catecontent" id="content">
<ul class="cate-list">
<li><h2><a href="">{$content.pictitle}</a></h2></li>
<li class="description">描述:{$content.picdescription}</li>
<li class="picture">{$content.pictureurl }这里是图片地址字段</li>
<li>
<span class="tag">标签:<a href="" target="_blank">{$content.pictag}</a></span>
<span class="author">上传者:{$content.picauthor}</span>
</li>
</ul>
</volist>
下面是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< count($str); $i++) {
$picstr.='<a href='.U('pls/index',array('id'=>$id)).' target="_blank"><img width="'.$width.'" src='.$str[$i].'></a> ';
}
return $picstr;
}
}
加个函数进去 模板里头调用函数就可以了 放全局函数里头 这个函数修改下
------解决思路----------------------
本来就是分开的,干嘛要合并在一起?
TP 的模型提供有 Relation 方法,本身就是为了解决你这种问题的
在 volist 里面在逃一个 volist 输出图片就可以了