This article mainly introduces the thinkphp implementation of the two-level loop read method, is thinkphp array-based database operation is very common skills, the need for friends can refer to the following
The example in this paper describes the method of thinkphp implementation of two-level cyclic reading. Share to everyone for your reference. The implementation method is as follows:
$Category = D (' Category ')->where (' Category_pid=0 ')->findall ();//dump ($Category); if (!empty ($Category)) {//Determines whether the primary level is an empty foreach ($Category as $key = = $value) { //cyclic read $pid = $value [' category_id '] ;//Field Assignment $category[$key] [' child '] = D (' category ')->where ("category_pid = $pid")->select ();//echo D (' category ')- >getlastsql (); Print SQL statement}}//dump ($Category); $this->assign (' Category ', $Category);//Map value
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!