This article mainly introduces ThinkPHP's method of implementing second-level loop reading. it is a very common technique in ThinkPHP array-based database operations. if you need ThinkPHP, refer to ThinkPHP.
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.