This article mainly introduces ThinkPHP's method for implementing second-level loop reading. It is a very common technique in ThinkPHP array-based database operations. For more information, see
This article mainly introduces ThinkPHP's method for implementing second-level loop reading. It is a very common technique in ThinkPHP array-based database operations. For more information, see
This example describes how ThinkPHP implements second-level cyclic reading. Share it with you for your reference. The specific implementation method is as follows:
The Code is as follows:
$ Category = D ('category ')-> where ('category _ pid = 0')-> findAll ();
// Dump ($ Category );
If (! Empty ($ Category) {// determines whether a level 1 is empty
Foreach ($ Category as $ key => $ value) {// read cyclically
$ Pid = $ value ['category _ id']; // field value assignment
$ Category [$ key] ['child '] = D ('category')-> where ("category_pid = $ pid")-> select ();
// Echo D ('category ')-> getLastSql (); // print the SQL statement syntax
}
}
// Dump ($ Category );
$ This-> assign ('category ', $ Category); // ing Value
I hope this article will help you with ThinkPHP framework programming.
,