您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關thinkphp3.2如何將視圖查詢結果的二維數組進行合并的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體如下:
使用視圖模型查詢的時候 結果是這樣的
array(6) { [0] => array(5) { ["picTitle"] => string(7) "標題2" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-26 11:59:50" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/547550278b7db.jpg" } [1] => array(5) { ["picTitle"] => string(7) "標題2" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-26 11:59:50" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/54755027ab89b.jpg" } [2] => array(5) { ["picTitle"] => string(7) "標題2" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-26 11:59:50" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/547550273b753.jpg" } [3] => array(5) { ["picTitle"] => string(7) "標題2" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-26 11:59:50" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141126/54755027d8488.jpg" } [4] => array(5) { ["picTitle"] => string(33) "同步寫入信息和附件表里" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-20 16:05:16" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141120/546da0746edb8.png" } [5] => array(5) { ["picTitle"] => string(33) "同步寫入信息和附件表里" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-20 16:05:16" ["pictureurl"] => string(55) "attachment/picture/uploadify/20141120/546da0784831c.png" } }
想要的結果是這樣
array(2) { ["0"] => array(5) { ["picTitle"] => string(7) "標題2" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-26 11:59:50" ["pictureurl"] => string(223) "attachment/picture/uploadify/20141126/547550278b7db.jpg,attachment/picture/uploadify/20141126/54755027ab89b.jpg,attachment/picture/uploadify/20141126/547550273b753.jpg,attachment/picture/uploadify/20141126/54755027d8488.jpg" } ["1"] => array(5) { ["picTitle"] => string(33) "同步寫入信息和附件表里" ["picCategroy"] => string(6) "海報" ["picAuthor"] => string(12) "星耀學園" ["picPostTime"] => string(19) "2014-11-20 16:05:16" ["pictureurl"] => string(111) "attachment/picture/uploadify/20141120/546da0746edb8.png,attachment/picture/uploadify/20141120/546da0784831c.png" } }
完整實例開始
控制器 里 根據生成的SQL 語句在phpmyadmin里運行 出現排序規則不一致的情況 兩個表的字段 排序規則不一致 整表排序規則一樣的情況下
PictureController.class.php
public function Pic(){ $PicModel =D('PicView'); /* dump($PicModel);*/ $s1= $PicModel->field('picTitle,picCategroy,picAuthor,picPostTime,pictureurl')->order('picPostTime desc')->select(); /* dump($PicModel->getLastSql()); 查詢最后的sql 語句*/ /* dump($s1);*/ $zhengli = $this->mergePictureURL($s1); /* dump( $zhengli );*/ $this->assign("content",$zhengli); $this->display(); }
視圖模型里
PicViewModel.class.php
<?php namespace Home\Model; use Think\Model\ViewModel; class PicViewModel extends ViewModel{ public $viewFields =array( 'Picture'=> array('picTitle','picToken','picCategroy','picAuthor','picPostTime','_as'=>'Picture'), 'PictureAttachment' =>array('pictureid','pictureurl','creattime','_on'=>'Picture.picToken = PictureAttachment.pictureid','_as'=>'PictureAttachment'), ); }
視圖里
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <volist name="content" id="data"> <!-- {$data.picTitle} {$data.picAuthor}發布時間:{$data.picPostTime}--> {$data.picTitle} </volist> </body> </html>
感謝各位的閱讀!關于“thinkphp3.2如何將視圖查詢結果的二維數組進行合并”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。